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

[CRV-244] Adapted create and update methods in order to manage all choreography data

parent 0cae2ee8
......@@ -43,6 +43,10 @@ public class ChoreographyTO extends AbstractBaseBean {
private String status;
private String synthesisProcessorKey;
private String enactmentEngineKey;
public String getKey() {
return key;
}
......@@ -115,4 +119,20 @@ public class ChoreographyTO extends AbstractBaseBean {
this.status = status;
}
public String getSynthesisProcessorKey() {
return synthesisProcessorKey;
}
public void setSynthesisProcessorKey(final String synthesisProcessorKey) {
this.synthesisProcessorKey = synthesisProcessorKey;
}
public String getEnactmentEngineKey() {
return enactmentEngineKey;
}
public void setEnactmentEngineKey(final String enactmentEngineKey) {
this.enactmentEngineKey = enactmentEngineKey;
}
}
......@@ -317,20 +317,37 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_CREATE + "')")
public String create(final String name, final String synthesisProcessorKey, final InputStream chorSpec) {
AnyObjectTO synthesisProcessor = synthesisProcessorExists(synthesisProcessorKey);
public String create(final ChoreographyTO choreographyTO) {
AnyObjectTO synthesisProcessor = synthesisProcessorExists(choreographyTO.getSynthesisProcessorKey());
GroupTO choreography = new GroupTO();
try {
// 1. create the choreography group
choreography.setName(name);
choreography.setName(choreographyTO.getName());
choreography.setRealm(SyncopeConstants.ROOT_REALM);
choreography.getAuxClasses().add("Choreography");
choreography.getPlainAttrs().add(
new AttrTO.Builder().schema(CHOREOGRAPHY_STATUS_SCHEMA).value("PENDING CREATE").build());
choreography.getPlainAttrs().add(
new AttrTO.Builder().schema("chorSpec").
value(Base64Utility.encode(IOUtils.readBytesFromStream(chorSpec))).build());
value(Base64Utility.encode(choreographyTO.getChorspec())).build());
choreography.getPlainAttrs().add(
new AttrTO.Builder().schema("diagram").
value(Base64Utility.encode(choreographyTO.getDiagram())).build());
choreography.getPlainAttrs().add(
new AttrTO.Builder().schema("messages").
value(Base64Utility.encode(choreographyTO.getMessages())).build());
if (choreographyTO.getImage() != null && choreographyTO.getImage().length > 0) {
choreography.getPlainAttrs().add(
new AttrTO.Builder().schema("image").
value(Base64Utility.encode(choreographyTO.getImage())).build());
}
if (choreographyTO.getDescription() != null) {
choreography.getPlainAttrs().add(
new AttrTO.Builder().schema("description").value(choreographyTO.getDescription()).build());
}
TypeExtensionTO serviceTE = new TypeExtensionTO();
serviceTE.setAnyType(SERVICE_TYPE);
......@@ -346,40 +363,34 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
anyObjectLogic.update(eePatch, false);
} catch (Exception e) {
throw new RuntimeException("While creating " + name, e);
throw new RuntimeException("While creating " + choreographyTO.getName(), e);
}
return choreography.getKey();
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_UPDATE + "')")
public void update(final String key, final String name, final InputStream chorSpec) {
GroupTO choreography = groupLogic.read(key);
public void update(final ChoreographyTO choreographyTO) {
GroupTO choreography = groupLogic.read(choreographyTO.getKey());
GroupPatch choreographyPatch = new GroupPatch();
choreographyPatch.setKey(choreography.getKey());
choreographyPatch.setKey(choreographyTO.getKey());
choreographyPatch.getTypeExtensions().addAll(choreography.getTypeExtensions());
try {
if (!choreography.getName().equals(name)) {
choreographyPatch.setName(new StringReplacePatchItem.Builder().value(name).build());
// Updates only choreography description and image
if (choreographyTO.getDescription() != null) {
choreographyPatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(
new AttrTO.Builder().schema("description").value(choreographyTO.getDescription()).build()).build());
}
Map<String, AttrTO> choreographyAttrs = choreography.getPlainAttrMap();
if (!choreographyAttrs.containsKey(CHOREOGRAPHY_STATUS_SCHEMA)
|| choreographyAttrs.get(CHOREOGRAPHY_STATUS_SCHEMA).getValues().isEmpty()
|| !"PENDING CREATE".equals(choreographyAttrs.get(CHOREOGRAPHY_STATUS_SCHEMA).getValues().get(0))) {
if (choreographyTO.getImage() != null && choreographyTO.getImage().length > 0) {
choreographyPatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(
new AttrTO.Builder().schema(CHOREOGRAPHY_STATUS_SCHEMA).value("PENDING UPDATE").build()).
build());
new AttrTO.Builder().schema("image").
value(Base64Utility.encode(choreographyTO.getImage())).build()).build());
}
choreographyPatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(
new AttrTO.Builder().schema("chorSpec").
value(Base64Utility.encode(IOUtils.readBytesFromStream(chorSpec))).build()).
build());
groupLogic.update(choreographyPatch, false);
} catch (Exception e) {
throw new RuntimeException("While updating " + name, e);
throw new RuntimeException("While updating " + choreographyTO.getName(), e);
}
}
......
......@@ -15,6 +15,7 @@
*/
package org.apache.syncope.common.rest.api.service;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.types.ChoreographyAction;
import eu.chorevolution.idm.common.types.ChoreographyOperation;
import eu.chorevolution.idm.common.types.SecurityFilterInfo;
......@@ -64,32 +65,22 @@ public interface ChoreographyService extends JAXRSService {
/**
* Creates a choreography.
*
* @param name choreography name
* @param synthesisProcessorKey associated synthesis processor instance
* @param chorSpec ChorSpec XML representation
* @param choreographyTO choreography
* @return Response object featuring Location header of created choreography
*/
@POST
@Consumes({ MediaType.APPLICATION_XML })
Response create(
@NotNull @QueryParam("name") String name,
@NotNull @QueryParam("synthesisProcessor") String synthesisProcessorKey,
InputStream chorSpec);
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Response create(ChoreographyTO choreographyTO);
/**
* Updates an existing choreography, with updated specification.
*
* @param key choreography key
* @param name choreography name
* @param chorSpec ChorSpec XML representation
* @param choreographyTO choreography
*/
@PUT
@Path("{key}")
@Consumes({ MediaType.APPLICATION_XML })
void update(
@NotNull @PathParam("key") String key,
@NotNull @QueryParam("name") String name,
InputStream chorSpec);
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
void update(ChoreographyTO choreographyTO);
/**
* Deletes the given choreography.
......
......@@ -39,8 +39,8 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
private ChoreographyLogic logic;
@Override
public Response create(final String name, final String synthesisProcessorKey, final InputStream chorSpec) {
String key = logic.create(name, synthesisProcessorKey, chorSpec);
public Response create(final ChoreographyTO choreographyTO) {
String key = logic.create(choreographyTO);
return Response.
created(uriInfo.getAbsolutePathBuilder().path(key).build()).
header(RESTHeaders.RESOURCE_KEY, key).
......@@ -58,8 +58,8 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
}
@Override
public void update(final String key, final String name, final InputStream chorSpec) {
logic.update(key, name, chorSpec);
public void update(final ChoreographyTO choreographyTO) {
logic.update(choreographyTO);
}
@Override
......
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