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> {
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_STATUS_SCHEMA = "status";
......@@ -266,6 +268,20 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
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 + "')")
public ChoreographyTO getChoreography(final String choreographyKey) {
GroupTO choreography = groupLogic.read(choreographyKey);
......@@ -276,12 +292,12 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_CREATE + "')")
public String create(final String name, final InputStream chorSpec) {
//AnyObjectTO enactmentEngine = enactmentEngineExists(enactmentEngineKey);
public String create(final String name, final String synthesisProcessorKey, final InputStream chorSpec) {
AnyObjectTO synthesisProcessor = synthesisProcessorExists(synthesisProcessorKey);
GroupTO choreography = new GroupTO();
try {
// create the choreography group
// 1. create the choreography group
choreography.setName(name);
choreography.setRealm(SyncopeConstants.ROOT_REALM);
choreography.getAuxClasses().add("Choreography");
......@@ -298,6 +314,12 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
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) {
throw new RuntimeException("While creating " + name, e);
}
......
......@@ -57,6 +57,7 @@ public interface ChoreographyService extends JAXRSService {
* Creates a choreography.
*
* @param name choreography name
* @param synthesisProcessorKey associated synthesis processor instance
* @param chorSpec ChorSpec XML representation
* @return Response object featuring Location header of created choreography
*/
......@@ -64,6 +65,7 @@ public interface ChoreographyService extends JAXRSService {
@Consumes({ MediaType.APPLICATION_XML })
Response create(
@NotNull @QueryParam("name") String name,
@NotNull @QueryParam("synthesisProcessor") String synthesisProcessorKey,
InputStream chorSpec);
/**
......
......@@ -37,8 +37,8 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
private ChoreographyLogic logic;
@Override
public Response create(final String name, final InputStream chorSpec) {
String key = logic.create(name, chorSpec);
public Response create(final String name, final String synthesisProcessorKey, final InputStream chorSpec) {
String key = logic.create(name, synthesisProcessorKey, chorSpec);
return Response.
created(uriInfo.getAbsolutePathBuilder().path(key).build()).
header(RESTHeaders.RESOURCE_KEY, key).
......
Markdown is supported
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