http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationDelete.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationDelete.java new file mode 100644 index 0000000..1e4b96d --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationDelete.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.notification; + +import javax.xml.ws.WebServiceException; +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.client.cli.messages.Messages; +import org.apache.syncope.common.lib.SyncopeClientException; + +public class NotificationDelete extends AbstractNotificationCommand { + + private static final String DELETE_HELP_MESSAGE = "notification --delete {NOTIFICATION-ID} {NOTIFICATION-ID} [...]"; + + private final Input input; + + public NotificationDelete(final Input input) { + this.input = input; + } + + public void delete() { + if (input.parameterNumber() >= 1) { + for (final String parameter : input.getParameters()) { + try { + notificationService.delete(Long.valueOf(parameter)); + notificationResultManager.deletedMessage("Notification", parameter); + } catch (final WebServiceException | SyncopeClientException ex) { + if (ex.getMessage().startsWith("NotFound")) { + notificationResultManager.notFoundError("Notification", parameter); + } else { + Messages.printMessage(ex.getMessage()); + } + } catch (final NumberFormatException ex) { + notificationResultManager.notBooleanDeletedError("notification", parameter); + } + } + } else { + notificationResultManager.commandOptionError(DELETE_HELP_MESSAGE); + } + } +}
http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationList.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationList.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationList.java new file mode 100644 index 0000000..ff9561c --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationList.java @@ -0,0 +1,35 @@ +/* + * 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.notification; + +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.NotificationTO; + +public class NotificationList extends AbstractNotificationCommand { + + public void list() { + try { + for (final NotificationTO notificationTO : notificationService.list()) { + System.out.println(notificationTO); + } + } catch (final SyncopeClientException ex) { + notificationResultManager.generic(ex.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationRead.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationRead.java new file mode 100644 index 0000000..386700c --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationRead.java @@ -0,0 +1,54 @@ +/* + * 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.notification; + +import javax.xml.ws.WebServiceException; +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.common.lib.SyncopeClientException; + +public class NotificationRead extends AbstractNotificationCommand { + + private static final String READ_HELP_MESSAGE = "notification --read {NOTIFICATION-ID} {NOTIFICATION-ID} [...]"; + + private final Input input; + + public NotificationRead(final Input input) { + this.input = input; + } + + public void read() { + if (input.parameterNumber() >= 1) { + for (final String parameter : input.getParameters()) { + try { + System.out.println(notificationService.read(Long.valueOf(parameter))); + } catch (final NumberFormatException ex) { + notificationResultManager.notBooleanDeletedError("notification", parameter); + } catch (final WebServiceException | SyncopeClientException ex) { + if (ex.getMessage().startsWith("NotFound")) { + notificationResultManager.notFoundError("Notification", parameter); + } else { + notificationResultManager.generic(ex.getMessage()); + } + } + } + } else { + notificationResultManager.commandOptionError(READ_HELP_MESSAGE); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationResultManager.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationResultManager.java new file mode 100644 index 0000000..d16d88b --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationResultManager.java @@ -0,0 +1,25 @@ +/* + * 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.notification; + +import org.apache.syncope.client.cli.commands.CommonsResultManager; + +public class NotificationResultManager extends CommonsResultManager { + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/AbstractSchemaCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/AbstractSchemaCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/AbstractSchemaCommand.java new file mode 100644 index 0000000..3074135 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/AbstractSchemaCommand.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.schema; + +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.common.rest.api.service.SchemaService; + +public abstract class AbstractSchemaCommand { + + protected final SchemaService schemaService = SyncopeServices.get(SchemaService.class); + + protected final SchemaResultManager schemaResultManager = new SchemaResultManager(); + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaCommand.java new file mode 100644 index 0000000..193c79b --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaCommand.java @@ -0,0 +1,127 @@ +/* + * 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.schema; + +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 = "schema") +public class SchemaCommand extends AbstractCommand { + + private static final String HELP_MESSAGE = "Usage: schema [options]\n" + + " Options:\n" + + " --help \n" + + " --list-all\n" + + " --list-plain\n" + + " --list-derived\n" + + " --list-virtual\n" + + " --read {SCHEMA-TYPE} {SCHEMA-KEY}\n" + + " Schema type: PLAIN / DERIVED / VIRTUAL\n" + + " --delete {SCHEMA-TYPE} {SCHEMA-KEY}\n" + + " Schema type: PLAIN / DERIVED / VIRTUAL"; + + @Override + public void execute(final Input input) { + if (StringUtils.isBlank(input.getOption())) { + input.setOption(Options.HELP.getOptionName()); + } + + switch (Options.fromName(input.getOption())) { + case LIST: + new SchemaList(input).list(); + break; + case LIST_ALL: + new SchemaListAll().listAll(); + break; + case LIST_PLAIN: + new SchemaListPlain().listPlain(); + break; + case LIST_DERIVED: + new SchemaListDerived().listDerived(); + break; + case LIST_VIRTUAL: + new SchemaListVirtual().listVirtual(); + break; + case READ: + new SchemaRead(input).read(); + break; + case DELETE: + new SchemaDelete(input).delete(); + break; + case HELP: + System.out.println(HELP_MESSAGE); + break; + default: + new SchemaResultManager().defaultError(input.getOption(), HELP_MESSAGE); + } + } + + @Override + public String getHelpMessage() { + return HELP_MESSAGE; + } + + private enum Options { + + HELP("--help"), + LIST("--list"), + LIST_ALL("--list-all"), + LIST_PLAIN("--list-plain"), + LIST_DERIVED("--list-derived"), + LIST_VIRTUAL("--list-virtual"), + READ("--read"), + DELETE("--delete"); + + private final String optionName; + + 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; + } + + public static List<String> toList() { + final List<String> options = new ArrayList<>(); + for (final Options value : values()) { + options.add(value.getOptionName()); + } + return options; + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaDelete.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaDelete.java new file mode 100644 index 0000000..9cf6fe2 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaDelete.java @@ -0,0 +1,64 @@ +/* + * 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.schema; + +import java.util.Arrays; +import javax.xml.ws.WebServiceException; +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.client.cli.util.CommandUtils; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.types.SchemaType; + +public class SchemaDelete extends AbstractSchemaCommand { + + private static final String DELETE_HELP_MESSAGE = "schema --delete {SCHEMA-TYPE} {SCHEMA-KEY}\n" + + " Schema type: PLAIN / DERIVED / VIRTUAL"; + + private final Input input; + + public SchemaDelete(final Input input) { + this.input = input; + } + + public void delete() { + if (input.parameterNumber() >= 2) { + final String[] parameters = Arrays.copyOfRange(input.getParameters(), 1, input.parameterNumber()); + try { + for (final String parameter : parameters) { + schemaService.delete(SchemaType.valueOf(input.firstParameter()), parameter); + schemaResultManager.deletedMessage("Schema", parameter); + } + } catch (final SyncopeClientException | WebServiceException ex) { + if (ex.getMessage().startsWith("NotFound")) { + schemaResultManager.notFoundError("Schema", parameters[0]); + } else if (ex.getMessage().startsWith("DataIntegrityViolation")) { + schemaResultManager.generic("You cannot delete schema " + parameters[0]); + } else { + schemaResultManager.generic(ex.getMessage()); + } + } catch (final IllegalArgumentException ex) { + schemaResultManager.typeNotValidError( + "schema", input.firstParameter(), CommandUtils.fromEnumToArray(SchemaType.class)); + } + } else { + schemaResultManager.commandOptionError(DELETE_HELP_MESSAGE); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaList.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaList.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaList.java new file mode 100644 index 0000000..5f51604 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaList.java @@ -0,0 +1,70 @@ +/* + * 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.schema; + +import java.util.LinkedList; +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.client.cli.util.CommandUtils; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractSchemaTO; +import org.apache.syncope.common.lib.types.SchemaType; + +public class SchemaList extends AbstractSchemaCommand { + + private static final String LIST_HELP_MESSAGE = "schema --list {SCHEMA-TYPE}\n" + + " Schema type: PLAIN / DERIVED / VIRTUAL"; + + private final Input input; + + public SchemaList(final Input input) { + this.input = input; + } + + public void list() { + if (input.parameterNumber() == 1) { + try { + final SchemaType schemaType = SchemaType.valueOf(input.firstParameter()); + final LinkedList<AbstractSchemaTO> schemaTOs = new LinkedList<>(); + for (final AbstractSchemaTO schemaTO : schemaService.list(schemaType)) { + schemaTOs.add(schemaTO); + } + switch (schemaType) { + case PLAIN: + schemaResultManager.fromListPlain(schemaTOs); + break; + case DERIVED: + schemaResultManager.fromListDerived(schemaTOs); + break; + case VIRTUAL: + schemaResultManager.fromListVirtual(schemaTOs); + break; + default: + break; + } + } catch (final SyncopeClientException ex) { + schemaResultManager.generic(ex.getMessage()); + } catch (final IllegalArgumentException ex) { + schemaResultManager.typeNotValidError( + "schema", input.firstParameter(), CommandUtils.fromEnumToArray(SchemaType.class)); + } + } else { + schemaResultManager.commandOptionError(LIST_HELP_MESSAGE); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListAll.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListAll.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListAll.java new file mode 100644 index 0000000..5d00adb --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListAll.java @@ -0,0 +1,55 @@ +/* + * 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.schema; + +import java.util.LinkedList; +import javax.xml.ws.WebServiceException; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractSchemaTO; +import org.apache.syncope.common.lib.types.SchemaType; + +public class SchemaListAll extends AbstractSchemaCommand { + + public void listAll() { + try { + for (final SchemaType schemaType : SchemaType.values()) { + final LinkedList<AbstractSchemaTO> schemaTOs = new LinkedList<>(); + for (final AbstractSchemaTO schemaTO : schemaService.list(schemaType)) { + schemaTOs.add(schemaTO); + } + switch (schemaType) { + case PLAIN: + schemaResultManager.fromListPlain(schemaTOs); + break; + case DERIVED: + schemaResultManager.fromListDerived(schemaTOs); + break; + case VIRTUAL: + schemaResultManager.fromListVirtual(schemaTOs); + break; + default: + break; + } + } + } catch (final SyncopeClientException | WebServiceException ex) { + schemaResultManager.generic(ex.getMessage()); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListDerived.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListDerived.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListDerived.java new file mode 100644 index 0000000..8cdb501 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListDerived.java @@ -0,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.commands.schema; + +import java.util.LinkedList; +import javax.xml.ws.WebServiceException; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractSchemaTO; +import org.apache.syncope.common.lib.types.SchemaType; + +public class SchemaListDerived extends AbstractSchemaCommand { + + public void listDerived() { + try { + final LinkedList<AbstractSchemaTO> schemaTOs = new LinkedList<>(); + for (final AbstractSchemaTO schemaTO : schemaService.list(SchemaType.DERIVED)) { + schemaTOs.add(schemaTO); + } + schemaResultManager.fromListDerived(schemaTOs); + } catch (final SyncopeClientException | WebServiceException ex) { + schemaResultManager.generic(ex.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListPlain.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListPlain.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListPlain.java new file mode 100644 index 0000000..e4160a7 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListPlain.java @@ -0,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.commands.schema; + +import java.util.LinkedList; +import javax.xml.ws.WebServiceException; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractSchemaTO; +import org.apache.syncope.common.lib.types.SchemaType; + +public class SchemaListPlain extends AbstractSchemaCommand { + + public void listPlain() { + try { + final LinkedList<AbstractSchemaTO> schemaTOs = new LinkedList<>(); + for (final AbstractSchemaTO schemaTO : schemaService.list(SchemaType.PLAIN)) { + schemaTOs.add(schemaTO); + } + schemaResultManager.fromListPlain(schemaTOs); + } catch (final SyncopeClientException | WebServiceException ex) { + schemaResultManager.generic(ex.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListVirtual.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListVirtual.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListVirtual.java new file mode 100644 index 0000000..7b1bf24 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaListVirtual.java @@ -0,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.commands.schema; + +import java.util.LinkedList; +import javax.xml.ws.WebServiceException; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractSchemaTO; +import org.apache.syncope.common.lib.types.SchemaType; + +public class SchemaListVirtual extends AbstractSchemaCommand { + + public void listVirtual() { + try { + final LinkedList<AbstractSchemaTO> schemaTOs = new LinkedList<>(); + for (final AbstractSchemaTO schemaTO : schemaService.list(SchemaType.VIRTUAL)) { + schemaTOs.add(schemaTO); + } + schemaResultManager.fromListVirtual(schemaTOs); + } catch (final SyncopeClientException | WebServiceException ex) { + schemaResultManager.generic(ex.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaRead.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaRead.java new file mode 100644 index 0000000..97f1029 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaRead.java @@ -0,0 +1,78 @@ +/* + * 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.schema; + +import java.util.Arrays; +import java.util.LinkedList; +import javax.xml.ws.WebServiceException; +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.client.cli.util.CommandUtils; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractSchemaTO; +import org.apache.syncope.common.lib.types.SchemaType; + +public class SchemaRead extends AbstractSchemaCommand { + + private static final String READ_HELP_MESSAGE = "schema --read {SCHEMA-TYPE} {SCHEMA-KEY}\n" + + " Schema type: PLAIN / DERIVED / VIRTUAL"; + + private final Input input; + + public SchemaRead(final Input input) { + this.input = input; + } + + public void read() { + if (input.parameterNumber() >= 2) { + final String[] parameters = Arrays.copyOfRange(input.getParameters(), 1, input.parameterNumber()); + try { + final SchemaType schemaType = SchemaType.valueOf(input.firstParameter()); + final LinkedList<AbstractSchemaTO> schemaTOs = new LinkedList<>(); + for (final String parameter : parameters) { + schemaTOs.add(schemaService.read(schemaType, parameter)); + } + switch (schemaType) { + case PLAIN: + schemaResultManager.fromReadPlain(schemaTOs); + break; + case DERIVED: + schemaResultManager.fromListDerived(schemaTOs); + break; + case VIRTUAL: + schemaResultManager.fromListVirtual(schemaTOs); + break; + default: + break; + } + } catch (final SyncopeClientException | WebServiceException ex) { + if (ex.getMessage().startsWith("NotFound")) { + schemaResultManager.notFoundError("Schema", parameters[0]); + } else { + schemaResultManager.generic(ex.getMessage()); + } + } catch (final IllegalArgumentException ex) { + schemaResultManager.typeNotValidError( + "schema", input.firstParameter(), CommandUtils.fromEnumToArray(SchemaType.class)); + } + } else { + schemaResultManager.commandOptionError(READ_HELP_MESSAGE); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaResultManager.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaResultManager.java new file mode 100644 index 0000000..8880dd3 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/schema/SchemaResultManager.java @@ -0,0 +1,96 @@ +/* + * 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.schema; + +import java.util.Arrays; +import java.util.LinkedList; +import org.apache.syncope.client.cli.commands.CommonsResultManager; +import org.apache.syncope.client.cli.messages.Table; +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; + +public class SchemaResultManager extends CommonsResultManager { + + public void fromListPlain(final LinkedList<? extends AbstractSchemaTO> schemaTOs) { + final Table.TableBuilder tableBuilder + = new Table.TableBuilder("plain schemas").header("schema key").header("type").header("mandatory"); + for (final AbstractSchemaTO schemaTO : schemaTOs) { + tableBuilder.rowValues(new LinkedList(Arrays.asList( + ((PlainSchemaTO) schemaTO).getKey(), + ((PlainSchemaTO) schemaTO).getType().toString(), + ((PlainSchemaTO) schemaTO).getMandatoryCondition()))); + } + tableBuilder.build().print(); + } + + public void fromReadPlain(final LinkedList<? extends AbstractSchemaTO> schemaTOs) { + final Table.TableBuilder tableBuilder + = new Table.TableBuilder("plain schema details ") + .header("schema key") + .header("type class") + .header("pattern") + .header("enum keys") + .header("enum values") + .header("mandatory condition") + .header("mime type") + .header("secret key") + .header("class validator") + .header("chiper") + .header("type"); + for (final AbstractSchemaTO schemaTO : schemaTOs) { + tableBuilder.rowValues(new LinkedList(Arrays.asList( + ((PlainSchemaTO) schemaTO).getKey(), + ((PlainSchemaTO) schemaTO).getAnyTypeClass(), + ((PlainSchemaTO) schemaTO).getConversionPattern(), + ((PlainSchemaTO) schemaTO).getEnumerationKeys(), + ((PlainSchemaTO) schemaTO).getEnumerationValues(), + ((PlainSchemaTO) schemaTO).getMandatoryCondition(), + ((PlainSchemaTO) schemaTO).getMimeType(), + ((PlainSchemaTO) schemaTO).getSecretKey(), + ((PlainSchemaTO) schemaTO).getValidatorClass(), + ((PlainSchemaTO) schemaTO).getCipherAlgorithm(), + ((PlainSchemaTO) schemaTO).getType().toString()))); + } + tableBuilder.build().print(); + } + + public void fromListDerived(final LinkedList<? extends AbstractSchemaTO> schemaTOs) { + final Table.TableBuilder tableBuilder + = new Table.TableBuilder("derived schemas").header("schema key").header("expression"); + for (final AbstractSchemaTO schemaTO : schemaTOs) { + tableBuilder.rowValues(new LinkedList(Arrays.asList( + ((DerSchemaTO) schemaTO).getKey(), + ((DerSchemaTO) schemaTO).getExpression()))); + } + tableBuilder.build().print(); + } + + public void fromListVirtual(final LinkedList<? extends AbstractSchemaTO> schemaTOs) { + final Table.TableBuilder tableBuilder + = new Table.TableBuilder("virtual schemas").header("schema key").header("readonly"); + for (final AbstractSchemaTO schemaTO : schemaTOs) { + tableBuilder.rowValues(new LinkedList(Arrays.asList( + ((VirSchemaTO) schemaTO).getKey(), + String.valueOf(((VirSchemaTO) schemaTO).isReadonly())))); + } + tableBuilder.build().print(); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/messages/Table.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/messages/Table.java b/client/cli/src/main/java/org/apache/syncope/client/cli/messages/Table.java index 8a28965..311682c 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/messages/Table.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/messages/Table.java @@ -94,7 +94,7 @@ public final class Table { for (final LinkedList<String> value : values) { for (int j = 0; j < columnsSize.length; j++) { - if (value.get(j).length() > columnsSize[j]) { + if (value.get(j) != null && value.get(j).length() > columnsSize[j]) { columnsSize[j] = value.get(j).length(); } } @@ -143,9 +143,13 @@ public final class Table { private void printeContent() { printColumnSpace(); - for (LinkedList<String> value : values) { + for (final LinkedList<String> value : values) { for (int j = 0; j < columnsNumber; j++) { - tmpValuesArray[j] = StringUtils.center(value.get(j), columnsSize[j]); + if (value.get(j) == null) { + tmpValuesArray[j] = StringUtils.center("null", columnsSize[j]); + } else { + tmpValuesArray[j] = StringUtils.center(value.get(j), columnsSize[j]); + } } System.out.format(tableContentFormat, tmpValuesArray); } @@ -160,7 +164,7 @@ public final class Table { System.out.format(tableContentFormat, tmpValuesArray); } - + public static class TableBuilder { private final LinkedList<String> headers = new LinkedList<>();