Commit ac612f21 authored by Gianluca Filippone's avatar Gianluca Filippone
Browse files

[CRV-299] Now choreography create function receives synthesis processor key...

[CRV-299] Now choreography create function receives synthesis processor key and instanciates relationship
parent 4bc138a1
...@@ -100,6 +100,8 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> { ...@@ -100,6 +100,8 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
private static final String ENACTMENT_ENGINE_PASSWORD = "enactmentEnginePassword"; private static final String ENACTMENT_ENGINE_PASSWORD = "enactmentEnginePassword";
private static final String SYNTHESIS_PROCESSOR_TYPE = "SYNTHESIS PROCESSOR";
private static final String CHOREOGRAPHY_ID_SCHEMA = "id"; private static final String CHOREOGRAPHY_ID_SCHEMA = "id";
private static final String CHOREOGRAPHY_STATUS_SCHEMA = "status"; private static final String CHOREOGRAPHY_STATUS_SCHEMA = "status";
...@@ -266,6 +268,20 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> { ...@@ -266,6 +268,20 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
return enactmentEngine; return enactmentEngine;
} }
private AnyObjectTO synthesisProcessorExists(final String synthesisProcessorKey) {
// ensures that synthesisProcessor contains effectively the entity key and that
// such object exists and has the expected type
AnyObjectTO synthesisProcessor = anyObjectLogic.read(synthesisProcessorKey);
if (!SYNTHESIS_PROCESSOR_TYPE.equals(synthesisProcessor.getType())) {
LOG.error("Could not find Synthesis Processor with key {}",
synthesisProcessor.getKey());
throw new BadRequestException("Could not find Synthesis Processor with key "
+ synthesisProcessor.getKey());
}
return synthesisProcessor;
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_READ + "')") @PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_READ + "')")
public ChoreographyTO getChoreography(final String choreographyKey) { public ChoreographyTO getChoreography(final String choreographyKey) {
GroupTO choreography = groupLogic.read(choreographyKey); GroupTO choreography = groupLogic.read(choreographyKey);
...@@ -276,12 +292,12 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> { ...@@ -276,12 +292,12 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
} }
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_CREATE + "')") @PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_CREATE + "')")
public String create(final String name, final InputStream chorSpec) { public String create(final String name, final String synthesisProcessorKey, final InputStream chorSpec) {
//AnyObjectTO enactmentEngine = enactmentEngineExists(enactmentEngineKey); AnyObjectTO synthesisProcessor = synthesisProcessorExists(synthesisProcessorKey);
GroupTO choreography = new GroupTO(); GroupTO choreography = new GroupTO();
try { try {
// create the choreography group // 1. create the choreography group
choreography.setName(name); choreography.setName(name);
choreography.setRealm(SyncopeConstants.ROOT_REALM); choreography.setRealm(SyncopeConstants.ROOT_REALM);
choreography.getAuxClasses().add("Choreography"); choreography.getAuxClasses().add("Choreography");
...@@ -298,6 +314,12 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> { ...@@ -298,6 +314,12 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
choreography = groupLogic.create(choreography, false).getEntity(); choreography = groupLogic.create(choreography, false).getEntity();
// 2. set the membership with the given synthesis processor
AnyObjectPatch eePatch = new AnyObjectPatch();
eePatch.setKey(synthesisProcessor.getKey());
eePatch.getMemberships().add(new MembershipPatch.Builder().group(choreography.getKey()).build());
anyObjectLogic.update(eePatch, false);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("While creating " + name, e); throw new RuntimeException("While creating " + name, e);
} }
......
...@@ -57,6 +57,7 @@ public interface ChoreographyService extends JAXRSService { ...@@ -57,6 +57,7 @@ public interface ChoreographyService extends JAXRSService {
* Creates a choreography. * Creates a choreography.
* *
* @param name choreography name * @param name choreography name
* @param synthesisProcessorKey associated synthesis processor instance
* @param chorSpec ChorSpec XML representation * @param chorSpec ChorSpec XML representation
* @return Response object featuring Location header of created choreography * @return Response object featuring Location header of created choreography
*/ */
...@@ -64,6 +65,7 @@ public interface ChoreographyService extends JAXRSService { ...@@ -64,6 +65,7 @@ public interface ChoreographyService extends JAXRSService {
@Consumes({ MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_XML })
Response create( Response create(
@NotNull @QueryParam("name") String name, @NotNull @QueryParam("name") String name,
@NotNull @QueryParam("synthesisProcessor") String synthesisProcessorKey,
InputStream chorSpec); InputStream chorSpec);
/** /**
......
...@@ -37,8 +37,8 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor ...@@ -37,8 +37,8 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
private ChoreographyLogic logic; private ChoreographyLogic logic;
@Override @Override
public Response create(final String name, final InputStream chorSpec) { public Response create(final String name, final String synthesisProcessorKey, final InputStream chorSpec) {
String key = logic.create(name, chorSpec); String key = logic.create(name, synthesisProcessorKey, chorSpec);
return Response. return Response.
created(uriInfo.getAbsolutePathBuilder().path(key).build()). created(uriInfo.getAbsolutePathBuilder().path(key).build()).
header(RESTHeaders.RESOURCE_KEY, key). header(RESTHeaders.RESOURCE_KEY, key).
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment