Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/syncope


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/4a28d6c8
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/4a28d6c8
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/4a28d6c8

Branch: refs/heads/master
Commit: 4a28d6c835e8f47658e5a8ef6d171249750f992e
Parents: 729cf5b 2f137b2
Author: massi <[email protected]>
Authored: Wed Oct 14 15:07:50 2015 +0200
Committer: massi <[email protected]>
Committed: Wed Oct 14 15:07:50 2015 +0200

----------------------------------------------------------------------
 .../client/cli/commands/SchemaCommand.java      | 251 ++++++++++++++++
 .../cli/commands/install/InstallCommand.java    | 298 +++++++++++++++++++
 .../install/InstallConfigFileTemplate.java      |  57 ++++
 .../client/cli/messages/UsageMessages.java      |  40 +++
 4 files changed, 646 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/4a28d6c8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java
----------------------------------------------------------------------
diff --cc 
client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java
index 0000000,0000000..3671cf0
new file mode 100644
--- /dev/null
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java
@@@ -1,0 -1,0 +1,251 @@@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements.  See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership.  The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License.  You may obtain a copy of the License at
++ *
++ *   http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++ * KIND, either express or implied.  See the License for the
++ * specific language governing permissions and limitations
++ * under the License.
++ */
++package org.apache.syncope.client.cli.commands;
++
++import java.util.Arrays;
++import javax.xml.ws.WebServiceException;
++import org.apache.commons.lang3.StringUtils;
++import org.apache.syncope.client.cli.Command;
++import org.apache.syncope.client.cli.Input;
++import org.apache.syncope.client.cli.SyncopeServices;
++import org.apache.syncope.common.lib.SyncopeClientException;
++import org.apache.syncope.common.lib.to.AbstractSchemaTO;
++import org.apache.syncope.common.lib.to.DerSchemaTO;
++import org.apache.syncope.common.lib.to.PlainSchemaTO;
++import org.apache.syncope.common.lib.to.VirSchemaTO;
++import org.apache.syncope.common.lib.types.SchemaType;
++import org.apache.syncope.common.rest.api.service.SchemaService;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
++
++@Command(name = "schema")
++public class SchemaCommand extends AbstractCommand {
++
++    private static final Logger LOG = 
LoggerFactory.getLogger(SchemaCommand.class);
++
++    private static final String HELP_MESSAGE = "Usage: schema [options]\n"
++            + "  Options:\n"
++            + "    --help \n"
++            + "    --list-all\n"
++            + "    --list {SCHEMA-TYPE}\n"
++            + "       Schema type: PLAIN / DERIVED / VIRTUAL";
++
++    @Override
++    public void execute(final Input input) {
++        LOG.debug("Option: {}", input.getOption());
++        LOG.debug("Parameters:");
++        for (final String parameter : input.getParameters()) {
++            LOG.debug("   > " + parameter);
++        }
++
++        String[] parameters = input.getParameters();
++
++        if (StringUtils.isBlank(input.getOption())) {
++            input.setOption(Options.HELP.getOptionName());
++        }
++
++        final SchemaService schemaService = 
SyncopeServices.get(SchemaService.class);
++        switch (Options.fromName(input.getOption())) {
++            case LIST:
++                final String listErrorMessage = "Usage: schema --list 
{SCHEMA-TYPE}\n"
++                        + "   Schema type: PLAIN / DERIVED / VIRTUAL";
++                if (parameters.length == 1) {
++                    try {
++                        final SchemaType schemaType = 
SchemaType.valueOf(input.firstParameter());
++                        for (final AbstractSchemaTO schemaTO : 
schemaService.list(schemaType)) {
++                            switch (schemaType) {
++                                case PLAIN:
++                                    System.out.println(" - Schema key: " + 
((PlainSchemaTO) schemaTO).getKey());
++                                    System.out.println("      type: " + 
((PlainSchemaTO) schemaTO).getType());
++                                    System.out.println("      is mandatory: "
++                                            + ((PlainSchemaTO) 
schemaTO).getMandatoryCondition());
++                                    break;
++                                case DERIVED:
++                                    System.out.println(" - Schema key: " + 
((DerSchemaTO) schemaTO).getKey());
++                                    System.out.println("      expression: " + 
((DerSchemaTO) schemaTO).getExpression());
++                                    break;
++                                case VIRTUAL:
++                                    System.out.println(" - Schema key: " + 
((VirSchemaTO) schemaTO).getKey());
++                                    break;
++                                default:
++                                    break;
++                            }
++                        }
++                    } catch (final SyncopeClientException ex) {
++                        System.out.println(" - Error: " + ex.getMessage());
++                    } catch (final IllegalArgumentException ex) {
++                        System.out.println(" - Error: " + 
input.firstParameter()
++                                + " isn't a valid schema type, try with:");
++                        for (final SchemaType type : SchemaType.values()) {
++                            System.out.println("  *** " + type.name());
++                        }
++                    }
++                } else {
++                    System.out.println(listErrorMessage);
++                }
++                break;
++            case LIST_ALL:
++                try {
++                    for (final SchemaType value : SchemaType.values()) {
++                        System.out.println("Schemas for " + value);
++                        for (final AbstractSchemaTO schemaTO : 
schemaService.list(value)) {
++                            System.out.println("   - Name: " + 
schemaTO.getKey() + " type: "
++                                    + schemaTO.getAnyTypeClass());
++                        }
++                    }
++                } catch (final SyncopeClientException | WebServiceException 
ex) {
++                    System.out.println(" - Error: " + ex.getMessage());
++                }
++                break;
++            case READ:
++                final String readErrorMessage = "Usage: schema --read 
{SCHEMA-TYPE} {SCHEMA-KEY}\n"
++                        + "   Schema type: PLAIN / DERIVED / VIRTUAL";
++                if (parameters.length >= 2) {
++                    parameters = Arrays.copyOfRange(parameters, 1, 
parameters.length);
++                    try {
++                        final SchemaType schemaType = 
SchemaType.valueOf(input.firstParameter());
++                        for (final String parameter : parameters) {
++                            final AbstractSchemaTO schemaTO = 
schemaService.read(schemaType, parameter);
++                            switch (schemaType) {
++                                case PLAIN:
++                                    System.out.println(" - Schema key: " + 
((PlainSchemaTO) schemaTO).getKey());
++                                    System.out.println("      any type class: 
"
++                                            + ((PlainSchemaTO) 
schemaTO).getAnyTypeClass());
++                                    System.out.println("      conversion 
pattern: "
++                                            + ((PlainSchemaTO) 
schemaTO).getConversionPattern());
++                                    System.out.println("      enumeration 
keys: "
++                                            + ((PlainSchemaTO) 
schemaTO).getEnumerationKeys());
++                                    System.out.println("      enumeration 
values: "
++                                            + ((PlainSchemaTO) 
schemaTO).getEnumerationValues());
++                                    System.out.println("      mandatory 
condition: "
++                                            + ((PlainSchemaTO) 
schemaTO).getMandatoryCondition());
++                                    System.out.println("      mime type: " + 
((PlainSchemaTO) schemaTO).getMimeType());
++                                    System.out.println("      secret key: "
++                                            + ((PlainSchemaTO) 
schemaTO).getSecretKey());
++                                    System.out.println("      validator 
class: "
++                                            + ((PlainSchemaTO) 
schemaTO).getValidatorClass());
++                                    System.out.println("      cipher 
algorithm: "
++                                            + ((PlainSchemaTO) 
schemaTO).getCipherAlgorithm());
++                                    System.out.println("      TYPE: "
++                                            + ((PlainSchemaTO) 
schemaTO).getType());
++                                    break;
++                                case DERIVED:
++                                    System.out.println(" - Schema key: " + 
((DerSchemaTO) schemaTO).getKey());
++                                    System.out.println("      any type class: 
"
++                                            + ((DerSchemaTO) 
schemaTO).getAnyTypeClass());
++                                    System.out.println("      expression: " + 
((DerSchemaTO) schemaTO).getExpression());
++                                    break;
++                                case VIRTUAL:
++                                    System.out.println(" - Schema key: " + 
((VirSchemaTO) schemaTO).getKey());
++                                    System.out.println("      any type class: 
"
++                                            + ((VirSchemaTO) 
schemaTO).getAnyTypeClass());
++                                    break;
++                                default:
++                                    break;
++                            }
++                        }
++                    } catch (final SyncopeClientException | 
WebServiceException ex) {
++                        if (ex.getMessage().startsWith("NotFound")) {
++                            System.out.println(" - Schema " + parameters[0] + 
" doesn't exists!");
++                        } else if 
(ex.getMessage().startsWith("DataIntegrityViolation")) {
++                            System.out.println(" - You cannot delete schema " 
+ parameters[0]);
++                        } else {
++                            System.out.println(ex.getMessage());
++                        }
++                    } catch (final IllegalArgumentException ex) {
++                        System.out.println(" - Error: " + parameters[0] + " 
isn't a valid schema type, try with:");
++                        for (final SchemaType type : SchemaType.values()) {
++                            System.out.println("  *** " + type.name());
++                        }
++                    }
++                } else {
++                    System.out.println(readErrorMessage);
++                }
++                break;
++            case DELETE:
++                final String deleteErrorMessage = "Usage: schema --delete 
{SCHEMA-TYPE} {SCHEMA-KEY}\n"
++                        + "   Schema type: PLAIN / DERIVED / VIRTUAL";
++                if (parameters.length >= 2) {
++                    parameters = Arrays.copyOfRange(parameters, 1, 
parameters.length);
++                    try {
++                        for (final String parameter : parameters) {
++                            
schemaService.delete(SchemaType.valueOf(input.firstParameter()), parameter);
++                            System.out.println("Schema " + parameter + " 
successfully deleted!");
++                        }
++                    } catch (final SyncopeClientException | 
WebServiceException ex) {
++                        if (ex.getMessage().startsWith("NotFound")) {
++                            System.out.println(" - Schema " + parameters[0] + 
" doesn't exists!");
++                        } else if 
(ex.getMessage().startsWith("DataIntegrityViolation")) {
++                            System.out.println(" - You cannot delete schema " 
+ parameters[0]);
++                        } else {
++                            System.out.println(ex.getMessage());
++                        }
++                    } catch (final IllegalArgumentException ex) {
++                        System.out.println(" - Error: " + parameters[0] + " 
isn't a valid schema type, try with:");
++                        for (final SchemaType type : SchemaType.values()) {
++                            System.out.println("  *** " + type.name());
++                        }
++                    }
++                } else {
++                    System.out.println(deleteErrorMessage);
++                }
++                break;
++            case HELP:
++                System.out.println(HELP_MESSAGE);
++                break;
++            default:
++                System.out.println(input.getOption() + " is not a valid 
option.");
++                System.out.println("");
++                System.out.println(HELP_MESSAGE);
++        }
++    }
++
++    private enum Options {
++
++        HELP("--help"),
++        LIST("--list"),
++        LIST_ALL("--list-all"),
++        READ("--read"),
++        DELETE("--delete");
++
++        private final String optionName;
++
++        private Options(final String optionName) {
++            this.optionName = optionName;
++        }
++
++        public String getOptionName() {
++            return optionName;
++        }
++
++        public boolean equalsOptionName(final String otherName) {
++            return (otherName == null) ? false : optionName.equals(otherName);
++        }
++
++        public static Options fromName(final String name) {
++            Options optionToReturn = HELP;
++            for (final Options option : Options.values()) {
++                if (option.equalsOptionName(name)) {
++                    optionToReturn = option;
++                }
++            }
++            return optionToReturn;
++        }
++    }
++}

http://git-wip-us.apache.org/repos/asf/syncope/blob/4a28d6c8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java
----------------------------------------------------------------------
diff --cc 
client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java
index 0000000,0000000..35441d1
new file mode 100644
--- /dev/null
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java
@@@ -1,0 -1,0 +1,298 @@@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements.  See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership.  The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License.  You may obtain a copy of the License at
++ *
++ *   http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++ * KIND, either express or implied.  See the License for the
++ * specific language governing permissions and limitations
++ * under the License.
++ */
++package org.apache.syncope.client.cli.commands.install;
++
++import java.io.FileNotFoundException;
++import java.io.UnsupportedEncodingException;
++import java.net.ConnectException;
++import java.net.UnknownHostException;
++import java.util.Scanner;
++import javax.ws.rs.ProcessingException;
++import org.apache.commons.lang3.StringUtils;
++import org.apache.syncope.client.cli.Command;
++import org.apache.syncope.client.cli.Input;
++import org.apache.syncope.client.cli.SyncopeServices;
++import org.apache.syncope.client.cli.commands.AbstractCommand;
++import org.apache.syncope.client.cli.commands.LoggerCommand;
++import org.apache.syncope.client.cli.util.FileSystemUtils;
++import org.apache.syncope.client.cli.util.JasyptUtils;
++import org.apache.syncope.common.rest.api.service.SyncopeService;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
++
++@Command(name = "install")
++public class InstallCommand extends AbstractCommand {
++
++    private static final Logger LOG = 
LoggerFactory.getLogger(LoggerCommand.class);
++
++    private static final String HELP_MESSAGE = "Usage: logger [options]\n"
++            + "  Options:\n"
++            + "    --help \n"
++            + "    --setup";
++
++    private String syncopeAdminUser;
++
++    private String syncopeAdminPassword;
++
++    private String syncopeServerSchema;
++
++    private String syncopeServerHostname = "localhost";
++
++    private String syncopeServerPort = "8080";
++
++    private String syncopeServerRestContext = "/syncope/rest/";
++
++    @Override
++    public void execute(final Input input) {
++        LOG.debug("Option: {}", input.getOption());
++        LOG.debug("Parameters:");
++        for (final String parameter : input.getParameters()) {
++            LOG.debug("   > " + parameter);
++        }
++
++        if (StringUtils.isBlank(input.getOption())) {
++            input.setOption(Options.HELP.getOptionName());
++        }
++
++        switch (Options.fromName(input.getOption())) {
++            case INSTALL:
++                final Scanner scanIn = new Scanner(System.in);
++
++                System.out.println("");
++                
System.out.println("###############################################");
++                System.out.println("#                                         
    #");
++                System.out.println("# Welcome to Syncope CLI installation 
process #");
++                System.out.println("#                                         
    #");
++                
System.out.println("###############################################");
++                System.out.println("");
++
++                System.out.println("Path to config files of Syncope CLI 
client will be: "
++                        + InstallConfigFileTemplate.DIR_PATH);
++
++                if 
(!FileSystemUtils.canWrite(InstallConfigFileTemplate.DIR_PATH)) {
++                    System.out.println("Permission denied on " + 
InstallConfigFileTemplate.DIR_PATH);
++                    break;
++                }
++                System.out.println("- File system permission checked");
++                System.out.println("");
++
++                System.out.println("Syncope server schema [http/https]:");
++                String syncopeServerSchemaFromSystemIn = scanIn.nextLine();
++                boolean schemaFounded = false;
++                while (!schemaFounded) {
++                    if 
(("http".equalsIgnoreCase(syncopeServerSchemaFromSystemIn))
++                            || 
("https".equalsIgnoreCase(syncopeServerSchemaFromSystemIn))) {
++                        syncopeServerSchema = syncopeServerSchemaFromSystemIn;
++                        schemaFounded = true;
++                    } else {
++                        System.out.println("Please use one of below values:");
++                        System.out.println("   - http");
++                        System.out.println("   - https");
++                        syncopeServerSchemaFromSystemIn = scanIn.nextLine();
++                    }
++                }
++
++                System.out.println("Syncope server hostname [e.g. " + 
syncopeServerHostname + "]:");
++                String syncopeServerHostnameFromSystemIn = scanIn.nextLine();
++                boolean syncopeServerHostnameFounded = false;
++                while (!syncopeServerHostnameFounded) {
++                    if 
(StringUtils.isNotBlank(syncopeServerHostnameFromSystemIn)) {
++                        syncopeServerHostname = 
syncopeServerHostnameFromSystemIn;
++                        syncopeServerHostnameFounded = true;
++                    } else {
++                        System.out.println("Syncope server hostname [e.g. " + 
syncopeServerHostname + "]:");
++                        syncopeServerHostnameFromSystemIn = scanIn.nextLine();
++                    }
++                }
++
++                System.out.println("Syncope server port [e.g. " + 
syncopeServerPort + "]:");
++                String syncopeServerPortFromSystemIn = scanIn.nextLine();
++                boolean syncopeServerPortFounded = false;
++                while (!syncopeServerPortFounded) {
++                    if 
(StringUtils.isNotBlank(syncopeServerPortFromSystemIn)) {
++                        syncopeServerPort = syncopeServerPortFromSystemIn;
++                        syncopeServerPortFounded = true;
++                    } else if 
(!StringUtils.isNumeric(syncopeServerPortFromSystemIn)) {
++                        System.out.println(syncopeServerPortFromSystemIn + " 
is not a numeric string, try again");
++                        syncopeServerPortFromSystemIn = scanIn.nextLine();
++                    } else {
++                        System.out.println("Syncope server port [e.g. " + 
syncopeServerPort + "]:");
++                        syncopeServerPortFromSystemIn = scanIn.nextLine();
++                    }
++                }
++
++                System.out.println("Syncope server rest context [e.g. " + 
syncopeServerRestContext + "]:");
++                String syncopeServerRestContextFromSystemIn = 
scanIn.nextLine();
++                boolean syncopeServerRestContextFounded = false;
++                while (!syncopeServerRestContextFounded) {
++                    if 
(StringUtils.isNotBlank(syncopeServerRestContextFromSystemIn)) {
++                        syncopeServerRestContext = 
syncopeServerRestContextFromSystemIn;
++                        syncopeServerRestContextFounded = true;
++                    } else {
++                        System.out.println("Syncope server port [e.g. " + 
syncopeServerRestContext + "]:");
++                        syncopeServerRestContextFromSystemIn = 
scanIn.nextLine();
++                    }
++                }
++
++                System.out.println("Syncope admin user:");
++                String syncopeAdminUserFromSystemIn = scanIn.nextLine();
++                boolean syncopeAdminUserFounded = false;
++                while (!syncopeAdminUserFounded) {
++                    if (StringUtils.isNotBlank(syncopeAdminUserFromSystemIn)) 
{
++                        syncopeAdminUser = syncopeAdminUserFromSystemIn;
++                        syncopeAdminUserFounded = true;
++                    } else {
++                        System.out.println("Syncope admin user:");
++                        syncopeAdminUserFromSystemIn = scanIn.nextLine();
++                    }
++                }
++
++                System.out.println("Syncope admin password:");
++                String syncopeAdminPasswordFromSystemIn = scanIn.nextLine();
++                boolean syncopeAdminPasswordFounded = false;
++                while (!syncopeAdminPasswordFounded) {
++                    if 
(StringUtils.isNotBlank(syncopeAdminPasswordFromSystemIn)) {
++                        syncopeAdminPassword = 
syncopeAdminPasswordFromSystemIn;
++                        syncopeAdminPasswordFounded = true;
++                    } else {
++                        System.out.println("Syncope admin user:");
++                        syncopeAdminPasswordFromSystemIn = scanIn.nextLine();
++                    }
++                }
++
++                scanIn.close();
++
++                final JasyptUtils jasyptUtils = JasyptUtils.getJasyptUtils();
++
++                try {
++                    
FileSystemUtils.createNewDirectory(InstallConfigFileTemplate.DIR_PATH);
++                    final String contentCliPropertiesFile = 
InstallConfigFileTemplate.createFile(
++                            syncopeServerSchema,
++                            syncopeServerHostname,
++                            syncopeServerPort,
++                            syncopeServerRestContext,
++                            syncopeAdminUser,
++                            jasyptUtils.encrypt(syncopeAdminPassword));
++                    
FileSystemUtils.createFileWith(InstallConfigFileTemplate.FILE_PATH, 
contentCliPropertiesFile);
++
++                } catch (final FileNotFoundException | 
UnsupportedEncodingException ex) {
++                    System.out.println(ex.getMessage());
++                }
++
++                try {
++                    final SyncopeService syncopeService = 
SyncopeServices.get(SyncopeService.class);
++                    System.out.println("Provided parameters checked on 
Syncope core version: "
++                            + syncopeService.info().getVersion());
++                    System.out.println("");
++                    
System.out.println("###############################################");
++                    System.out.println("#                                     
        #");
++                    System.out.println("#           Installation successful   
        #");
++                    System.out.println("#     now you can use Syncope CLI 
client      #");
++                    System.out.println("#                                     
        #");
++                    
System.out.println("###############################################");
++                    System.out.println("");
++                } catch (final ProcessingException ex) {
++                    if (ex.getCause() instanceof UnknownHostException) {
++                        final String unknownHost = 
ex.getCause().getMessage().split(":")[3];
++                        System.out.println("");
++                        System.out.println("Provided host:" + unknownHost);
++                        System.out.println("");
++                        
System.out.println("###############################################");
++                        System.out.println("#                                 
            #");
++                        System.out.println("#            Provided unknown 
host!           #");
++                        System.out.println("#        START AGAIN the 
installation!        #");
++                        System.out.println("#                                 
            #");
++                        
System.out.println("###############################################");
++                        System.out.println("");
++                    } else if (ex.getCause() instanceof ConnectException) {
++                        System.out.println("");
++                        System.out.println("Provided address :" + 
SyncopeServices.getAddress());
++                        System.out.println("");
++                        
System.out.println("###############################################");
++                        System.out.println("#                                 
            #");
++                        System.out.println("#       Provided address is 
unreachable!      #");
++                        System.out.println("#         Check it and if it is 
wrong         #");
++                        System.out.println("#        START AGAIN the 
installation!        #");
++                        System.out.println("#                                 
            #");
++                        
System.out.println("###############################################");
++                        System.out.println("");
++                    }
++                } catch (final Exception e) {
++                    if (e.getMessage().contains("not authenticated")) {
++                        System.out.println("");
++                        
System.out.println("###############################################");
++                        System.out.println("#                                 
            #");
++                        System.out.println("#   Username or password provided 
are wrong   #");
++                        System.out.println("#        START AGAIN the 
installation!        #");
++                        System.out.println("#                                 
            #");
++                        
System.out.println("###############################################");
++                        System.out.println("");
++                    } else {
++                        System.out.println("");
++                        
System.out.println("###############################################");
++                        System.out.println("#                                 
            #");
++                        System.out.println("#                Something wrong  
            #");
++                        System.out.println("#        START AGAIN the 
installation!        #");
++                        System.out.println("#                                 
            #");
++                        
System.out.println("###############################################");
++                        System.out.println("");
++                    }
++                }
++                break;
++            case HELP:
++                System.out.println(HELP_MESSAGE);
++                break;
++            default:
++                System.out.println(input.getOption() + " is not a valid 
option.");
++                System.out.println("");
++                System.out.println(HELP_MESSAGE);
++        }
++    }
++
++    private enum Options {
++
++        HELP("--help"),
++        INSTALL("--setup");
++
++        private final String optionName;
++
++        private Options(final String optionName) {
++            this.optionName = optionName;
++        }
++
++        public String getOptionName() {
++            return optionName;
++        }
++
++        public boolean equalsOptionName(final String otherName) {
++            return (otherName == null) ? false : optionName.equals(otherName);
++        }
++
++        public static Options fromName(final String name) {
++            Options optionToReturn = HELP;
++            for (final Options option : Options.values()) {
++                if (option.equalsOptionName(name)) {
++                    optionToReturn = option;
++                }
++            }
++            return optionToReturn;
++        }
++    }
++
++}

http://git-wip-us.apache.org/repos/asf/syncope/blob/4a28d6c8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallConfigFileTemplate.java
----------------------------------------------------------------------
diff --cc 
client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallConfigFileTemplate.java
index 0000000,0000000..6ef5cc0
new file mode 100644
--- /dev/null
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallConfigFileTemplate.java
@@@ -1,0 -1,0 +1,57 @@@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements.  See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership.  The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License.  You may obtain a copy of the License at
++ *
++ *   http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++ * KIND, either express or implied.  See the License for the
++ * specific language governing permissions and limitations
++ * under the License.
++ */
++package org.apache.syncope.client.cli.commands.install;
++
++import java.util.ResourceBundle;
++
++public final class InstallConfigFileTemplate {
++
++    private static final ResourceBundle CONF = 
ResourceBundle.getBundle("configuration");
++
++    public static final String DIR_PATH
++            = CONF.getString("cli.installation.directory");
++
++    public static final String FILE_NAME
++            = CONF.getString("cli.installation.filename");
++
++    public static final String FILE_PATH = DIR_PATH + FILE_NAME;
++
++    private static final String SYNCOPE_REST_SERVICES = 
"syncope.rest.services=%s://%s:%s%s";
++
++    private static final String SYNCOPE_ADMIN_USER = "syncope.admin.user=%s";
++
++    private static final String SYNCOPE_ADMIN_PASSWORD = 
"syncope.admin.password=%s";
++
++    public static String createFile(
++            final String schema,
++            final String hostname,
++            final String port,
++            final String restContext,
++            final String user,
++            final String password) {
++        final String syncopeRestServices = 
String.format(SYNCOPE_REST_SERVICES, schema, hostname, port, restContext);
++        final String syncopeAdminUser = String.format(SYNCOPE_ADMIN_USER, 
user);
++        final String syncopeAdminPassword = 
String.format(SYNCOPE_ADMIN_PASSWORD, password);
++
++        return syncopeRestServices + "\n" + syncopeAdminUser + "\n" + 
syncopeAdminPassword;
++    }
++
++    private InstallConfigFileTemplate() {
++    }
++}

http://git-wip-us.apache.org/repos/asf/syncope/blob/4a28d6c8/client/cli/src/main/java/org/apache/syncope/client/cli/messages/UsageMessages.java
----------------------------------------------------------------------
diff --cc 
client/cli/src/main/java/org/apache/syncope/client/cli/messages/UsageMessages.java
index 0000000,0000000..5661b60
new file mode 100644
--- /dev/null
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/messages/UsageMessages.java
@@@ -1,0 -1,0 +1,40 @@@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one
++ * or more contributor license agreements.  See the NOTICE file
++ * distributed with this work for additional information
++ * regarding copyright ownership.  The ASF licenses this file
++ * to you under the Apache License, Version 2.0 (the
++ * "License"); you may not use this file except in compliance
++ * with the License.  You may obtain a copy of the License at
++ *
++ *   http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing,
++ * software distributed under the License is distributed on an
++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++ * KIND, either express or implied.  See the License for the
++ * specific language governing permissions and limitations
++ * under the License.
++ */
++package org.apache.syncope.client.cli.messages;
++
++public final class UsageMessages {
++
++    private static final String OPTION_COMMAND_MESSAGE_TEMPLATE = "\n - 
Usage: %s\n";
++
++    public static final String optionCommandMessage(final String message) {
++        return String.format(OPTION_COMMAND_MESSAGE_TEMPLATE, message);
++    }
++
++    public static void printErrorMessage(final String... errors) {
++        final StringBuilder errorMessage = new StringBuilder("\n").append(" - 
");
++        for (final String error : errors) {
++            errorMessage.append(error).append("\n");
++        }
++        System.out.println(errorMessage.toString());
++    }
++
++    private UsageMessages() {
++
++    }
++}

Reply via email to