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

Code refactoring

parent ded1717a
......@@ -97,7 +97,8 @@ public class InstancePanel extends AbstractSearchResultPanel<
protected List<IColumn<ChoreographyInstanceTO, String>> getColumns() {
final List<IColumn<ChoreographyInstanceTO, String>> columns = new ArrayList<>();
columns.add(new PropertyColumn<>(new ResourceModel("choreographyInstanceId", "Id"), "choreographyInstanceId"));
columns.add(new PropertyColumn<>(new ResourceModel("description"), "Description", "description"));
columns.add(new PropertyColumn<>(new ResourceModel(
"instanceDescription", "Description"), "instanceDescription"));
columns.add(new AbstractColumn<ChoreographyInstanceTO, String>(new ResourceModel("actions", "")) {
private static final long serialVersionUID = -3503023501954863131L;
......
......@@ -29,10 +29,11 @@ public class ChoreographyInstanceTO extends AbstractBaseBean {
private Long choreographyInstanceId;
private String description;
private String instanceDescription;
private Long choreographyId;
private String choreographyName;
public long getId() {
return id;
......@@ -50,12 +51,12 @@ public class ChoreographyInstanceTO extends AbstractBaseBean {
this.choreographyInstanceId = choreographyInstanceId;
}
public String getDescription() {
return description;
public String getInstanceDescription() {
return instanceDescription;
}
public void setDescription(final String description) {
this.description = description;
public void setInstanceDescription(final String instanceDescription) {
this.instanceDescription = instanceDescription;
}
public Long getChoreographyId() {
......@@ -66,4 +67,12 @@ public class ChoreographyInstanceTO extends AbstractBaseBean {
this.choreographyId = choreographyId;
}
public String getChoreographyName() {
return choreographyName;
}
public void setChoreographyName(final String choreographyName) {
this.choreographyName = choreographyName;
}
}
......@@ -16,6 +16,7 @@
package org.apache.syncope.core.logic;
import eu.chorevolution.idm.common.BusinessException;
import eu.chorevolution.idm.common.to.ChoreographyInstanceTO;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.EventDataTO;
import java.lang.reflect.Method;
......@@ -53,27 +54,13 @@ public class CollectorLogic extends AbstractTransactionalLogic<AbstractBaseBean>
public void saveLogEvent(final EventDataTO data) throws BusinessException {
//Check whether instance of given choreography exists, add new one if not
//Check whether instance of given choreography exists
ChoreographyInstance choreographyInstance = choreographyInstanceDAO.findByChoreographyInstanceId(
data.getChoreographyName(), data.getChoreographyInstanceId()
);
if (choreographyInstance == null) {
Choreography choreography = choreographyDAO.findByName(data.getChoreographyName());
if (choreography == null) {
throw new BusinessException("Cannot find choreography");
}
choreographyInstance = new JPAChoreographyInstance();
choreographyInstance.setChoreography(choreography);
choreographyInstance.setChoreographyInstanceId(data.getChoreographyInstanceId());
choreographyInstance.setDestription("No description available");
choreography.addChoreographyInstance(choreographyInstance);
choreographyInstanceDAO.save(choreographyInstance);
throw new BusinessException("Cannot find choreography instance");
}
//Log event
......@@ -105,7 +92,22 @@ public class CollectorLogic extends AbstractTransactionalLogic<AbstractBaseBean>
choreographyDAO.save(choreography);
}
public void addInstance(final ChoreographyInstanceTO data) throws BusinessException {
Choreography choreography = choreographyDAO.findByName(data.getChoreographyName());
if (choreography == null) {
throw new BusinessException("Cannot find choreography");
}
ChoreographyInstance choreographyInstance = new JPAChoreographyInstance();
choreographyInstance.setChoreographyInstanceId(data.getChoreographyInstanceId());
choreographyInstance.setDestription(data.getInstanceDescription());
choreography.addChoreographyInstance(choreographyInstance);
choreographyInstanceDAO.save(choreographyInstance);
}
......
......@@ -89,7 +89,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
to = new ChoreographyInstanceTO();
to.setId(current.getKey());
to.setChoreographyInstanceId(current.getChoreographyInstanceId());
to.setDescription(current.getDescription());
to.setInstanceDescription(current.getDescription());
to.setChoreographyId(choreographyId);
......
......@@ -15,6 +15,7 @@
*/
package org.apache.syncope.common.rest.api.service;
import eu.chorevolution.idm.common.to.ChoreographyInstanceTO;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
......@@ -47,6 +48,11 @@ public interface CollectorService extends JAXRSService {
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
void addChoreography(@NotNull ChoreographyTO choreography);
@Path("instance")
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
void addInstance(@NotNull ChoreographyInstanceTO choreographyInstanceTO);
/**
* Test method
*
......
......@@ -15,6 +15,7 @@
*/
package org.apache.syncope.core.rest.cxf.service;
import eu.chorevolution.idm.common.to.ChoreographyInstanceTO;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.EventDataTO;
import javax.ws.rs.core.Response;
......@@ -30,13 +31,18 @@ public class CollectorServiceImpl extends AbstractServiceImpl implements Collect
private CollectorLogic logic;
@Override
public void logEvent(final EventDataTO data) {
logic.saveLogEvent(data);
public void logEvent(final EventDataTO eventData) {
logic.saveLogEvent(eventData);
}
@Override
public void addChoreography(final ChoreographyTO data) {
logic.addChoreography(data);
public void addChoreography(final ChoreographyTO choreography) {
logic.addChoreography(choreography);
}
@Override
public void addInstance(final ChoreographyInstanceTO choreographyInstanceTO) {
logic.addInstance(choreographyInstanceTO);
}
@Override
......
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