@Override public CommandAPI getCommandAPI() { return new CommandAPIImpl(); }
@Override public Serializable execute(final long commandId, final Map<String, Serializable> parameters) throws CommandNotFoundException, CommandParameterizationException, CommandExecutionException { return execute(new SCommandFetcherById(commandId), parameters); }
private Serializable execute(final SCommandFetcher commandFetcher, final Map<String, Serializable> parameters) throws CommandNotFoundException, CommandParameterizationException, CommandExecutionException { return executeCommand(commandFetcher, parameters, false); }
@Override public void unregister(final long commandId) throws CommandNotFoundException, DeletionException { final CommandService commandService = getTenantAccessor().getCommandService(); final DeleteSCommand deleteCommand = new DeleteSCommand(commandService, commandId); unregister(deleteCommand); }
@Override public void unregisterAll() throws DeletionException { final CommandService commandService = getTenantAccessor().getCommandService(); try { commandService.deleteAll(); } catch (final SCommandDeletionException sde) { throw new DeletionException(sde); } }
private Serializable executeCommand(final SCommandFetcher commandFetcher, final Map<String, Serializable> parameters, final boolean transactionManagedManually) throws CommandNotFoundException, CommandParameterizationException, CommandExecutionException { final TenantServiceAccessor tenantAccessor = getTenantAccessor(); try { final TenantCommand tenantCommand = fetchTenantCommand(commandFetcher, transactionManagedManually); return tenantCommand.execute(parameters, tenantAccessor); } catch (final SCommandExecutionException scee) { throw new CommandExecutionException(scee); } catch (final SCommandParameterizationException scpe) { throw new CommandParameterizationException(scpe); } catch (final SCommandNotFoundException e) { throw new CommandNotFoundException(e); } }
private void update(final SCommandFetcher commandFetcher, final CommandUpdater updateDescriptor) throws UpdateException { if (updateDescriptor == null || updateDescriptor.getFields().isEmpty()) { throw new UpdateException("The update descriptor does not contain field updates"); } final SCommandUpdateBuilderFactory fact = BuilderFactory.get(SCommandUpdateBuilderFactory.class); final SCommandUpdateBuilder commandUpdateBuilder = fact.createNewInstance(); final CommandService commandService = getTenantAccessor().getCommandService(); try { final EntityUpdateDescriptor changeDescriptor = getCommandUpdateDescriptor(updateDescriptor, commandUpdateBuilder); final SCommand sCommand = commandFetcher.fetch(commandService); commandService.update(sCommand, changeDescriptor); } catch (final SCommandNotFoundException | SCommandUpdateException e) { throw new UpdateException(e); } }
@Override public CommandDescriptor register(final String name, final String description, final String implementation) throws AlreadyExistsException, CreationException { CommandDescriptor existingCommandDescriptor = null; try { existingCommandDescriptor = getCommand(name); } catch (final CommandNotFoundException notFoundE) { // Nothing to do : no command with that name exists. } if (existingCommandDescriptor != null) { throw new AlreadyExistsException("A command with name \"" + name + "\" already exists"); } final TenantServiceAccessor tenantAccessor = getTenantAccessor(); final CommandService commandService = tenantAccessor.getCommandService(); final SCommandBuilderFactory fact = BuilderFactory.get(SCommandBuilderFactory.class); final SCommand sCommand = fact.createNewInstance(name, description, implementation).setSystem(false).done(); try { commandService.create(sCommand); return ModelConvertor.toCommandDescriptor(sCommand); } catch (final SBonitaException sbe) { throw new CreationException(sbe); } }
@Override @CustomTransactions public Serializable executeWithUserTransactions(final String commandName, final Map<String, Serializable> parameters) throws CommandNotFoundException, CommandParameterizationException, CommandExecutionException { return executeWithUserTransactions(new SCommandFetcherByName(commandName), parameters); }
@Override public CommandDescriptor get(final long commandId) throws CommandNotFoundException { return getCommand(new SCommandFetcherById(commandId)); }
@Override public void update(final long commandId, final CommandUpdater updateDescriptor) throws UpdateException { update(new SCommandFetcherById(commandId), updateDescriptor); }
@Override public void unregister(final long commandId) throws CommandNotFoundException, DeletionException { final CommandService commandService = getTenantAccessor().getCommandService(); final DeleteSCommand deleteCommand = new DeleteSCommand(commandService, commandId); unregister(deleteCommand); }
@Override public void unregisterAll() throws DeletionException { final CommandService commandService = getTenantAccessor().getCommandService(); try { commandService.deleteAll(); } catch (final SCommandDeletionException sde) { throw new DeletionException(sde); } }
private Serializable executeCommand(final SCommandFetcher commandFetcher, final Map<String, Serializable> parameters, final boolean transactionManagedManually) throws CommandNotFoundException, CommandParameterizationException, CommandExecutionException { final TenantServiceAccessor tenantAccessor = getTenantAccessor(); try { final TenantCommand tenantCommand = fetchTenantCommand(commandFetcher, transactionManagedManually); return tenantCommand.execute(parameters, tenantAccessor); } catch (final SCommandExecutionException scee) { throw new CommandExecutionException(scee); } catch (final SCommandParameterizationException scpe) { throw new CommandParameterizationException(scpe); } catch (final SCommandNotFoundException e) { throw new CommandNotFoundException(e); } }
private void update(final SCommandFetcher commandFetcher, final CommandUpdater updateDescriptor) throws UpdateException { if (updateDescriptor == null || updateDescriptor.getFields().isEmpty()) { throw new UpdateException("The update descriptor does not contain field updates"); } final SCommandUpdateBuilderFactory fact = BuilderFactory.get(SCommandUpdateBuilderFactory.class); final SCommandUpdateBuilder commandUpdateBuilder = fact.createNewInstance(); final CommandService commandService = getTenantAccessor().getCommandService(); try { final EntityUpdateDescriptor changeDescriptor = getCommandUpdateDescriptor(updateDescriptor, commandUpdateBuilder); final SCommand sCommand = commandFetcher.fetch(commandService); commandService.update(sCommand, changeDescriptor); } catch (final SCommandNotFoundException | SCommandUpdateException e) { throw new UpdateException(e); } }
@Override public CommandDescriptor register(final String name, final String description, final String implementation) throws AlreadyExistsException, CreationException { CommandDescriptor existingCommandDescriptor = null; try { existingCommandDescriptor = getCommand(name); } catch (final CommandNotFoundException notFoundE) { // Nothing to do : no command with that name exists. } if (existingCommandDescriptor != null) { throw new AlreadyExistsException("A command with name \"" + name + "\" already exists"); } final TenantServiceAccessor tenantAccessor = getTenantAccessor(); final CommandService commandService = tenantAccessor.getCommandService(); final SCommandBuilderFactory fact = BuilderFactory.get(SCommandBuilderFactory.class); final SCommand sCommand = fact.createNewInstance(name, description, implementation).setSystem(false).done(); try { commandService.create(sCommand); return ModelConvertor.toCommandDescriptor(sCommand); } catch (final SBonitaException sbe) { throw new CreationException(sbe); } }
@Override @CustomTransactions public Serializable executeWithUserTransactions(final long commandId, final Map<String, Serializable> parameters) throws CommandNotFoundException, CommandParameterizationException, CommandExecutionException { return executeWithUserTransactions(new SCommandFetcherById(commandId), parameters); }
@Override public CommandDescriptor getCommand(final String commandName) throws CommandNotFoundException { return getCommand(new SCommandFetcherByName(commandName)); }
@Override public void update(final String commandName, final CommandUpdater updateDescriptor) throws UpdateException { update(new SCommandFetcherByName(commandName), updateDescriptor); }
@Override public void unregister(final String name) throws CommandNotFoundException, DeletionException { if (name == null) { // FIXME: throw IllegalArgumentException instead, and make bonita interceptor catch all exceptions and wrap it into BonitaRuntimeException: throw new DeletionException("Command name can not be null!"); } final CommandService commandService = getTenantAccessor().getCommandService(); final DeleteSCommand deleteCommand = new DeleteSCommand(commandService, name); unregister(deleteCommand); }