use of org.eclipse.emfcloud.modelserver.common.codecs.DecodingException in project emfcloud-modelserver by eclipse-emfcloud.
the class DefaultModelResourceManagerTest method beforeTests.
@Before
public void beforeTests() throws DecodingException {
when(serverConfig.getWorkspaceRootURI()).thenReturn(URI.createFileURI(getCWD().getAbsolutePath() + "/" + RESOURCE_PATH));
modelResourceManager = Guice.createInjector(new AbstractModule() {
private Multibinder<EPackageConfiguration> ePackageConfigurationBinder;
private ArrayList<Class<? extends EPackageConfiguration>> ePackageConfigurations;
@Override
protected void configure() {
ePackageConfigurations = Lists.newArrayList(EcorePackageConfiguration.class, CommandPackageConfiguration.class);
ePackageConfigurationBinder = Multibinder.newSetBinder(binder(), EPackageConfiguration.class);
ePackageConfigurations.forEach(c -> ePackageConfigurationBinder.addBinding().to(c));
bind(ServerConfiguration.class).toInstance(serverConfig);
bind(CommandCodec.class).toInstance(commandCodec);
bind(ModelWatchersManager.class).toInstance(watchersManager);
bind(AdapterFactory.class).toInstance(new EcoreAdapterFactory());
bind(ModelRepository.class).to(DefaultModelRepository.class).in(Scopes.SINGLETON);
bind(ModelResourceManager.class).to(DefaultModelResourceManager.class).in(Scopes.SINGLETON);
bind(JsonPatchHelper.class).toInstance(jsonPatchHelper);
}
}).getInstance(DefaultModelResourceManager.class);
}
use of org.eclipse.emfcloud.modelserver.common.codecs.DecodingException in project emfcloud-modelserver by eclipse-emfcloud.
the class DefaultModelResourceManager method execute.
@Override
public CCommandExecutionResult execute(final String modeluri, final CCommand clientCommand) {
try {
ResourceSet resourceSet = getResourceSet(modeluri);
ModelServerEditingDomain domain = getEditingDomain(resourceSet);
URI uri = createURI(modeluri);
// resolve client command
ReadResourceSet readResourceSet = new ReadResourceSet(domain);
readResourceSet.resolve(clientCommand, "$command.res");
// translate to server EMF command
Command command = commandCodec.clientToServer(uri, domain, clientCommand);
Command modelServerCommand = ModelServerCommand.wrap(command, clientCommand);
// execute command
CommandExecutionContext context = executeCommand(domain, modelServerCommand, clientCommand);
// create result
CCommandExecutionResult result = createExecutionResult(context);
readResourceSet.resolve(result, "$command.exec.res");
return result;
} catch (DecodingException exception) {
LOG.error("Encoding of " + clientCommand + " failed: " + exception.getMessage());
throw new IllegalArgumentException(exception);
}
}
use of org.eclipse.emfcloud.modelserver.common.codecs.DecodingException in project emfcloud-modelserver by eclipse-emfcloud.
the class RemoveCommandContribution method serverCommand.
public static RemoveCommand serverCommand(final EditingDomain domain, final CCommand command) throws DecodingException {
EObject owner = command.getOwner();
EStructuralFeature feature = owner.eClass().getEStructuralFeature(command.getFeature());
if (!command.getIndices().isEmpty()) {
return (RemoveCommand) RemoveCommand.create(domain, owner, feature, Ints.toArray(command.getIndices()));
}
if (!command.getObjectValues().isEmpty()) {
return (RemoveCommand) RemoveCommand.create(domain, owner, feature, command.getObjectValues());
}
if (!command.getDataValues().isEmpty()) {
return (RemoveCommand) RemoveCommand.create(domain, owner, feature, command.getDataValues());
}
throw new DecodingException("incomplete remove command specification");
}
use of org.eclipse.emfcloud.modelserver.common.codecs.DecodingException in project emfcloud-modelserver by eclipse-emfcloud.
the class DefaultModelController method executePatchCommand.
protected void executePatchCommand(final Context ctx, final String modelURI, final EObject root, final PatchCommand<?> pCommand) {
CCommandExecutionResult result;
if (isCCommand(pCommand)) {
try {
result = this.modelRepository.executeCommand(modelURI, getCCommand(pCommand));
} catch (DecodingException ex) {
decodingError(ctx, ex);
return;
}
} else if (isJsonPatch(pCommand)) {
ArrayNode jsonPatch = getJsonPatch(pCommand);
try {
result = this.modelRepository.executeCommand(modelURI, jsonPatch);
} catch (JsonPatchTestException | JsonPatchException ex) {
LOG.error(ex.getMessage(), ex);
return;
}
} else {
// TODO Handle unsupported Patch/Command type
return;
}
JsonNode patchResult = getJSONPatchUpdate(ctx, modelURI, root, result);
if (patchResult != null) {
successPatch(ctx, patchResult, "Model '%s' successfully updated", modelURI);
sessionController.commandExecuted(modelURI, Suppliers.ofInstance(result), Suppliers.ofInstance(patchResult));
} else {
success(ctx, "Model '%s' successfully updated", modelURI);
}
}
use of org.eclipse.emfcloud.modelserver.common.codecs.DecodingException in project emfcloud-modelserver by eclipse-emfcloud.
the class DefaultModelController method executeCommand.
@Override
public void executeCommand(final Context ctx, final String modelURI) {
withModel(ctx, modelURI, root -> {
Optional<CCommand> command = readPayload(ctx).filter(CCommand.class::isInstance).map(CCommand.class::cast);
if (command.isEmpty()) {
return;
}
try {
CCommandExecutionResult execution = modelRepository.executeCommand(modelURI, command.get());
success(ctx, "Model '%s' successfully updated", modelURI);
sessionController.commandExecuted(modelURI, Suppliers.ofInstance(execution), Suppliers.memoize(() -> getJSONPatchUpdate(ctx, modelURI, root, execution)));
} catch (DecodingException exception) {
decodingError(ctx, exception);
}
});
}
Aggregations