Repository: syncope Updated Branches: refs/heads/master 9a1474770 -> 25c41ad81
Fixed SYNCOPE-588 Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/25c41ad8 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/25c41ad8 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/25c41ad8 Branch: refs/heads/master Commit: 25c41ad81b491d1df7606f0b88db0c3d6cf079a6 Parents: 9a14747 Author: massi <massimiliano.perr...@tirasa.net> Authored: Fri Oct 23 17:25:18 2015 +0200 Committer: massi <massimiliano.perr...@tirasa.net> Committed: Fri Oct 23 17:25:18 2015 +0200 ---------------------------------------------------------------------- .../cli/commands/CommonsResultManager.java | 18 +++ .../connector/ConnectorResultManager.java | 16 --- .../resource/AbstractResourceCommand.java | 30 +++++ .../cli/commands/resource/ResourceCommand.java | 109 +++++++++++++++++++ .../cli/commands/resource/ResourceDelete.java | 56 ++++++++++ .../cli/commands/resource/ResourceList.java | 32 ++++++ .../cli/commands/resource/ResourceRead.java | 60 ++++++++++ .../resource/ResourceResultManager.java | 95 ++++++++++++++++ 8 files changed, 400 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/25c41ad8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java index 7c17550..251297b 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java @@ -18,7 +18,9 @@ */ package org.apache.syncope.client.cli.commands; +import java.util.Set; import org.apache.syncope.client.cli.view.Messages; +import org.apache.syncope.common.lib.types.ConnConfProperty; public abstract class CommonsResultManager { @@ -53,4 +55,20 @@ public abstract class CommonsResultManager { public void generic(final String... messages) { Messages.printMessage(messages); } + + protected void printConfiguration(final Set<ConnConfProperty> configurationPropertys) { + for (final ConnConfProperty configuration : configurationPropertys) { + System.out.println(" name: " + configuration.getSchema().getName()); + System.out.println(" values: " + configuration.getValues()); + System.out.println(" type: " + configuration.getSchema().getType()); + System.out.println(" display name: " + configuration.getSchema().getDisplayName()); + System.out.println(" help message: " + configuration.getSchema().getHelpMessage()); + System.out.println(" order: " + configuration.getSchema().getOrder()); + System.out.println(" default values: " + configuration.getSchema().getDefaultValues()); + System.out.println(" confidential: " + configuration.getSchema().isConfidential()); + System.out.println(" required: " + configuration.getSchema().isRequired()); + System.out.println(" overridable: " + configuration.isOverridable()); + System.out.println(""); + } + } } http://git-wip-us.apache.org/repos/asf/syncope/blob/25c41ad8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/connector/ConnectorResultManager.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/connector/ConnectorResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/connector/ConnectorResultManager.java index 913c22e..b6edbc2 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/connector/ConnectorResultManager.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/connector/ConnectorResultManager.java @@ -76,22 +76,6 @@ public class ConnectorResultManager extends CommonsResultManager { } } - private void printConfiguration(final Set<ConnConfProperty> configurationPropertys) { - for (final ConnConfProperty configuration : configurationPropertys) { - System.out.println(" name: " + configuration.getSchema().getName()); - System.out.println(" values: " + configuration.getValues()); - System.out.println(" type: " + configuration.getSchema().getType()); - System.out.println(" display name: " + configuration.getSchema().getDisplayName()); - System.out.println(" help message: " + configuration.getSchema().getHelpMessage()); - System.out.println(" order: " + configuration.getSchema().getOrder()); - System.out.println(" default values: " + configuration.getSchema().getDefaultValues()); - System.out.println(" confidential: " + configuration.getSchema().isConfidential()); - System.out.println(" required: " + configuration.getSchema().isRequired()); - System.out.println(" overridable: " + configuration.isOverridable()); - System.out.println(""); - } - } - private void printConfPool(final ConnPoolConfTO connPoolConfTO) { System.out.println(" min idle: " + connPoolConfTO.getMinIdle()); System.out.println(" min evictlable idle: " + connPoolConfTO.getMinEvictableIdleTimeMillis()); http://git-wip-us.apache.org/repos/asf/syncope/blob/25c41ad8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/AbstractResourceCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/AbstractResourceCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/AbstractResourceCommand.java new file mode 100644 index 0000000..85d4a2d --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/AbstractResourceCommand.java @@ -0,0 +1,30 @@ +/* + * 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.resource; + +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.common.rest.api.service.ResourceService; + +public abstract class AbstractResourceCommand { + + protected final ResourceService resourceService = SyncopeServices.get(ResourceService.class); + + protected final ResourceResultManager resourceResultManager = new ResourceResultManager(); + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/25c41ad8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceCommand.java new file mode 100644 index 0000000..942fcd2 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceCommand.java @@ -0,0 +1,109 @@ +/* + * 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.resource; + +import java.util.ArrayList; +import java.util.List; +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.commands.AbstractCommand; + +@Command(name = "resource") +public class ResourceCommand extends AbstractCommand { + + private static final String HELP_MESSAGE = "Usage: resource [options]\n" + + " Options:\n" + + " --help \n" + + " --list \n" + + " --read \n" + + " Syntax: --read {CONNECTOR-ID} {CONNECTOR-ID} [...]\n" + + " --delete \n" + + " Syntax: --delete {CONNECTOR-ID} {CONNECTOR-ID} [...]"; + + @Override + public void execute(final Input input) { + if (StringUtils.isBlank(input.getOption())) { + input.setOption(ResourceOptions.HELP.getOptionName()); + } + + switch (ResourceOptions.fromName(input.getOption())) { + case LIST: + new ResourceList().list(); + break; + case READ: + new ResourceRead(input).read(); + break; + case DELETE: + new ResourceDelete(input).delete(); + break; + case HELP: + System.out.println(HELP_MESSAGE); + break; + default: + new ResourceResultManager().defaultError(input.getOption(), HELP_MESSAGE); + } + } + + @Override + public String getHelpMessage() { + return HELP_MESSAGE; + } + + private enum ResourceOptions { + + HELP("--help"), + LIST("--list"), + READ("--read"), + DELETE("--delete"); + + private final String optionName; + + ResourceOptions(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 ResourceOptions fromName(final String name) { + ResourceOptions optionToReturn = HELP; + for (final ResourceOptions option : ResourceOptions.values()) { + if (option.equalsOptionName(name)) { + optionToReturn = option; + } + } + return optionToReturn; + } + + public static List<String> toList() { + final List<String> options = new ArrayList<>(); + for (final ResourceOptions value : values()) { + options.add(value.getOptionName()); + } + return options; + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/25c41ad8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceDelete.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceDelete.java new file mode 100644 index 0000000..c3ecd84 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceDelete.java @@ -0,0 +1,56 @@ +/* + * 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.resource; +import javax.xml.ws.WebServiceException; +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.common.lib.SyncopeClientException; + +public class ResourceDelete extends AbstractResourceCommand { + + private static final String DELETE_HELP_MESSAGE = "resource --delete {RESOURCE-NAME} {RESOURCE-NAME} [...]"; + + private final Input input; + + public ResourceDelete(final Input input) { + this.input = input; + } + + public void delete() { + if (input.getParameters().length >= 1) { + for (final String parameter : input.getParameters()) { + try { + resourceService.delete(parameter); + resourceResultManager.deletedMessage("resource", parameter); + } catch (final NumberFormatException ex) { + resourceResultManager.managerNumberFormatException("resource", parameter); + } catch (final SyncopeClientException | WebServiceException ex) { + if (ex.getMessage().startsWith("NotFound")) { + resourceResultManager.notFoundError("Resource", parameter); + } else { + resourceResultManager.generic(ex.getMessage()); + } + break; + } + } + } else { + resourceResultManager.commandOptionError(DELETE_HELP_MESSAGE); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/25c41ad8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceList.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceList.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceList.java new file mode 100644 index 0000000..85f05f5 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceList.java @@ -0,0 +1,32 @@ +/* + * 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.resource; + +import org.apache.syncope.common.lib.SyncopeClientException; + +public class ResourceList extends AbstractResourceCommand { + + public void list() { + try { + resourceResultManager.toView(resourceService.list()); + } catch (final SyncopeClientException ex) { + resourceResultManager.generic(ex.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/25c41ad8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceRead.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceRead.java new file mode 100644 index 0000000..3790c02 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceRead.java @@ -0,0 +1,60 @@ +/* + * 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.resource; +import java.util.ArrayList; +import java.util.List; +import javax.xml.ws.WebServiceException; +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.ResourceTO; + +public class ResourceRead extends AbstractResourceCommand { + + private static final String READ_HELP_MESSAGE = "resource --read {RESOURCE-NAME} {RESOURCE-NAME} [...]"; + + private final Input input; + + public ResourceRead(final Input input) { + this.input = input; + } + + public void read() { + if (input.getParameters().length >= 1) { + final List<ResourceTO> resourceTOs = new ArrayList<>(); + for (final String parameter : input.getParameters()) { + try { + resourceTOs.add(resourceService.read(parameter)); + } catch (final NumberFormatException ex) { + resourceResultManager.managerNumberFormatException("resource", parameter); + } catch (final SyncopeClientException | WebServiceException ex) { + if (ex.getMessage().startsWith("NotFound")) { + resourceResultManager.notFoundError("Resource", parameter); + } else { + resourceResultManager.generic(ex.getMessage()); + } + break; + } + } + resourceResultManager.toView(resourceTOs); + } else { + resourceResultManager.commandOptionError(READ_HELP_MESSAGE); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/25c41ad8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceResultManager.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceResultManager.java new file mode 100644 index 0000000..91847f4 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/resource/ResourceResultManager.java @@ -0,0 +1,95 @@ +/* + * 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.resource; + +import java.util.List; +import org.apache.syncope.client.cli.commands.CommonsResultManager; +import org.apache.syncope.common.lib.to.MappingItemTO; +import org.apache.syncope.common.lib.to.MappingTO; +import org.apache.syncope.common.lib.to.ProvisionTO; +import org.apache.syncope.common.lib.to.ResourceTO; + +public class ResourceResultManager extends CommonsResultManager { + + public void toView(final List<ResourceTO> resourceTOs) { + for (final ResourceTO resourceTO : resourceTOs) { + printResource(resourceTO); + } + System.out.println(""); + } + + private void printResource(final ResourceTO resourceTO) { + System.out.println(" > RESOURCE ID: " + resourceTO.getKey()); + System.out.println(" connector dispaly name: " + resourceTO.getConnectorDisplayName()); + System.out.println(" etag value: " + resourceTO.getETagValue()); + System.out.println(" connector id: " + resourceTO.getConnector()); + System.out.println(" account policy id: " + resourceTO.getAccountPolicy()); + System.out.println(" password policy id: " + resourceTO.getPasswordPolicy()); + System.out.println(" sync policy id: " + resourceTO.getSyncPolicy()); + System.out.println(" creator: " + resourceTO.getCreator()); + System.out.println(" creation date: " + resourceTO.getCreationDate()); + System.out.println(" last modifier: " + resourceTO.getLastModifier()); + System.out.println(" last change date: " + resourceTO.getLastChangeDate()); + System.out.println(" propagation actions class: " + resourceTO.getPropagationActionsClassNames()); + System.out.println(" propagation priority: " + resourceTO.getPropagationPriority()); + System.out.println(" PROVISIONS:"); + printProvision(resourceTO.getProvisions()); + System.out.println(" create trace level: " + resourceTO.getCreateTraceLevel()); + System.out.println(" delete trace level: " + resourceTO.getDeleteTraceLevel()); + System.out.println(" update trace level: " + resourceTO.getUpdateTraceLevel()); + System.out.println(" sync trace level: " + resourceTO.getSyncTraceLevel()); + } + + private void printProvision(final List<ProvisionTO> provisionTOs) { + for (final ProvisionTO provisionTO : provisionTOs) { + System.out.println(" provision id: " + provisionTO.getKey()); + System.out.println(" any type: " + provisionTO.getAnyType()); + System.out.println(" object class: " + provisionTO.getObjectClass()); + System.out.println(" sync token: " + provisionTO.getSyncToken()); + System.out.println(" virtual schema: " + provisionTO.getVirSchemas()); + System.out.println(" MAPPING: "); + printMapping(provisionTO.getMapping()); + } + System.out.println(""); + } + + private void printMapping(final MappingTO mappingTO) { + System.out.println(" ConnObjectLink: " + mappingTO.getConnObjectLink()); + System.out.println(" MAPPING ITEM: "); + printMappingItem(mappingTO.getItems()); + System.out.println(""); + } + + private void printMappingItem(final List<MappingItemTO> mappingItemTOs) { + for (final MappingItemTO mappingItemTO : mappingItemTOs) { + System.out.println(" mapping key: " + mappingItemTO.getKey()); + System.out.println(" mapping item type: " + mappingItemTO.getIntMappingType().name()); + System.out.println(" internal attribute name: " + mappingItemTO.getIntAttrName()); + System.out.println(" external attribute name: " + mappingItemTO.getExtAttrName()); + System.out.println(" mandatory condition: " + mappingItemTO.getMandatoryCondition()); + System.out.println(" transformers class: " + + mappingItemTO.getMappingItemTransformerClassNames()); + System.out.println(" purpose: " + mappingItemTO.getPurpose()); + System.out.println(" connector object key: " + mappingItemTO.isConnObjectKey()); + System.out.println(" password: " + mappingItemTO.isPassword()); + } + System.out.println(""); + } + +}