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

[CRV-302] Created new REST method for listing choreographies and adapted...

[CRV-302] Created new REST method for listing choreographies and adapted methods  to store methods and choreography diagram
parent 8edfe455
......@@ -33,6 +33,8 @@ public class ChoreographyTO extends AbstractBaseBean {
private String description;
private byte[] chorSpec;
private byte[] diagram;
private byte[] messages;
......@@ -73,6 +75,14 @@ public class ChoreographyTO extends AbstractBaseBean {
this.description = description;
}
public byte[] getChorSpec() {
return chorSpec;
}
public void setChorSpec(final byte[] chorSpec) {
this.chorSpec = chorSpec;
}
public byte[] getDiagram() {
return diagram;
}
......
......@@ -36,6 +36,7 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
......@@ -71,6 +72,7 @@ import org.apache.syncope.common.lib.types.AttrSchemaType;
import org.apache.syncope.common.lib.types.CipherAlgorithm;
import org.apache.syncope.common.lib.types.PatchOperation;
import org.apache.syncope.common.lib.types.SchemaType;
import org.apache.syncope.core.persistence.api.dao.ChoreographyDAO;
import org.apache.syncope.core.persistence.api.dao.ChoreographyInstanceDAO;
import org.apache.syncope.core.persistence.api.dao.NotFoundException;
import org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond;
......@@ -78,6 +80,8 @@ import org.apache.syncope.core.persistence.api.dao.search.AttributeCond;
import org.apache.syncope.core.persistence.api.dao.search.MembershipCond;
import org.apache.syncope.core.persistence.api.dao.search.OrderByClause;
import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
import org.apache.syncope.core.persistence.api.entity.group.GPlainAttr;
import org.apache.syncope.core.persistence.api.entity.group.Group;
import org.apache.syncope.core.spring.security.Encryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -132,6 +136,9 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
@Autowired
private ChoreographyDAO choreographyDAO;
@Autowired
private GroupLogic groupLogic;
......@@ -291,8 +298,31 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
return getChoreography(choreography, true);
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_LIST + "')")
public List<ChoreographyTO> getChoreographyList() {
List<ChoreographyTO> result = new LinkedList<>();
for (Group choreography : choreographyDAO.findAll()) {
ChoreographyTO choreographyTO = new ChoreographyTO();
choreographyTO.setKey(choreography.getKey());
choreographyTO.setName(choreography.getName());
GPlainAttr description = choreography.getPlainAttr("description");
if (description != null && !description.getValues().isEmpty()) {
choreographyTO.setDescription(description.getValues().get(0).getStringValue());
}
result.add(choreographyTO);
}
return result;
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_CREATE + "')")
public String create(final String name, final String synthesisProcessorKey, final InputStream chorSpec) {
public String create(
final String name,
final String synthesisProcessorKey,
final InputStream chorSpec,
final InputStream diagram,
final InputStream messages) {
AnyObjectTO synthesisProcessor = synthesisProcessorExists(synthesisProcessorKey);
GroupTO choreography = new GroupTO();
......@@ -306,6 +336,12 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
choreography.getPlainAttrs().add(
new AttrTO.Builder().schema("chorSpec").
value(Base64Utility.encode(IOUtils.readBytesFromStream(chorSpec))).build());
choreography.getPlainAttrs().add(
new AttrTO.Builder().schema("diagram").
value(Base64Utility.encode(IOUtils.readBytesFromStream(diagram))).build());
choreography.getPlainAttrs().add(
new AttrTO.Builder().schema("messages").
value(Base64Utility.encode(IOUtils.readBytesFromStream(messages))).build());
TypeExtensionTO serviceTE = new TypeExtensionTO();
serviceTE.setAnyType(SERVICE_TYPE);
......@@ -328,7 +364,12 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_UPDATE + "')")
public void update(final String key, final String name, final InputStream chorSpec) {
public void update(
final String key,
final String name,
final InputStream chorSpec,
final InputStream diagram,
final InputStream messages) {
GroupTO choreography = groupLogic.read(key);
GroupPatch choreographyPatch = new GroupPatch();
......@@ -349,8 +390,13 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
choreographyPatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(
new AttrTO.Builder().schema("chorSpec").
value(Base64Utility.encode(IOUtils.readBytesFromStream(chorSpec))).build()).
build());
value(Base64Utility.encode(IOUtils.readBytesFromStream(chorSpec))).build()).build());
choreographyPatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(
new AttrTO.Builder().schema("diagram").
value(Base64Utility.encode(IOUtils.readBytesFromStream(diagram))).build()).build());
choreographyPatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(
new AttrTO.Builder().schema("messages").
value(Base64Utility.encode(IOUtils.readBytesFromStream(messages))).build()).build());
groupLogic.update(choreographyPatch, false);
} catch (Exception e) {
......@@ -923,6 +969,11 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
if (details) {
AttrTO chorspec = choreography.getPlainAttrMap().get("chorSpec");
if (chorspec != null && !chorspec.getValues().isEmpty()) {
choreographyTO.setMessages(DatatypeConverter.parseBase64Binary(chorspec.getValues().get(0)));
}
AttrTO messages = choreography.getPlainAttrMap().get("messages");
if (messages != null && !messages.getValues().isEmpty()) {
choreographyTO.setMessages(DatatypeConverter.parseBase64Binary(messages.getValues().get(0)));
......
......@@ -22,6 +22,7 @@ import eu.chorevolution.idm.common.types.SecurityFilterInfo;
import eu.chorevolution.idm.common.types.ServiceAction;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
......@@ -53,12 +54,23 @@ public interface ChoreographyService extends JAXRSService {
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
ChoreographyTO read(@NotNull @PathParam("key") String choreographyKey);
/**
* Retrieves choreography list
*
* @return list of all choreographies, with only name, key and description
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
List<ChoreographyTO> list();
/**
* Creates a choreography.
*
* @param name choreography name
* @param synthesisProcessorKey associated synthesis processor instance
* @param chorSpec ChorSpec XML representation
* @param diagram XML for the choreography diagram
* @param messages XML for message types
* @return Response object featuring Location header of created choreography
*/
@POST
......@@ -66,13 +78,17 @@ public interface ChoreographyService extends JAXRSService {
Response create(
@NotNull @QueryParam("name") String name,
@NotNull @QueryParam("synthesisProcessor") String synthesisProcessorKey,
InputStream chorSpec);
InputStream chorSpec,
InputStream diagram,
InputStream messages);
/**
* Updates an existing choreography, with updated specification.
*
* @param key choreography key
* @param name choreography name
* @param diagram XML for the choreography diagram
* @param messages XML for message types
* @param chorSpec ChorSpec XML representation
*/
@PUT
......@@ -81,7 +97,9 @@ public interface ChoreographyService extends JAXRSService {
void update(
@NotNull @PathParam("key") String key,
@NotNull @QueryParam("name") String name,
InputStream chorSpec);
InputStream chorSpec,
InputStream diagram,
InputStream messages);
/**
* Deletes the given choreography.
......
......@@ -23,6 +23,7 @@ import eu.chorevolution.idm.common.types.ServiceAction;
import org.apache.syncope.core.logic.ChoreographyLogic;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import javax.ws.rs.core.Response;
import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.syncope.common.rest.api.RESTHeaders;
......@@ -37,8 +38,13 @@ 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 String name,
final String synthesisProcessorKey,
final InputStream chorSpec,
final InputStream diagram,
final InputStream messages) {
String key = logic.create(name, synthesisProcessorKey, chorSpec, diagram, messages);
return Response.
created(uriInfo.getAbsolutePathBuilder().path(key).build()).
header(RESTHeaders.RESOURCE_KEY, key).
......@@ -51,8 +57,18 @@ 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 List<ChoreographyTO> list() {
return logic.getChoreographyList();
}
@Override
public void update(
final String key,
final String name,
final InputStream chorSpec,
final InputStream diagram,
final InputStream messages) {
logic.update(key, name, chorSpec, diagram, messages);
}
@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