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

Code refactoring

parent 89868e43
......@@ -92,9 +92,8 @@ public class ChoreographyPanel extends AbstractSearchResultPanel<
@Override
protected List<IColumn<ChoreographyTO, String>> getColumns() {
final List<IColumn<ChoreographyTO, String>> columns = new ArrayList<>();
//columns.add(new PropertyColumn<>(new ResourceModel("key"), "key", "key"));
columns.add(new PropertyColumn<>(new ResourceModel("name"), "name", "name"));
columns.add(new PropertyColumn<>(new ResourceModel("description"), "description", "description"));
columns.add(new PropertyColumn<>(new ResourceModel("name"), "Name", "name"));
columns.add(new PropertyColumn<>(new ResourceModel("description"), "Description", "description"));
columns.add(new AbstractColumn<ChoreographyTO, String>(new ResourceModel("actions", "")) {
private static final long serialVersionUID = -3503023501954863131L;
......
......@@ -96,10 +96,8 @@ public class InstancePanel extends AbstractSearchResultPanel<
@Override
protected List<IColumn<ChoreographyInstanceTO, String>> getColumns() {
final List<IColumn<ChoreographyInstanceTO, String>> columns = new ArrayList<>();
//columns.add(new PropertyColumn<>(new ResourceModel("key"), "key", "key"));
// columns.add(new PropertyColumn<>(new ResourceModel("choreographyKey", "Choreography Id"), "choreographyKey"));
columns.add(new PropertyColumn<>(new ResourceModel("name"), "name", "name"));
columns.add(new PropertyColumn<>(new ResourceModel("description"), "description", "description"));
columns.add(new PropertyColumn<>(new ResourceModel("choreographyInstanceId", "Id"), "choreographyInstanceId"));
columns.add(new PropertyColumn<>(new ResourceModel("description"), "Description", "description"));
columns.add(new AbstractColumn<ChoreographyInstanceTO, String>(new ResourceModel("actions", "")) {
private static final long serialVersionUID = -3503023501954863131L;
......
/*
* Copyright 2016 The CHOReVOLUTION project.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.chorevolution.idm.common;
import java.util.HashSet;
import java.util.Set;
public class BusinessException extends RuntimeException {
public BusinessException() {
super();
}
public BusinessException(final String message, final Throwable cause) {
super(message, cause);
}
public BusinessException(final String message) {
super(message);
}
public BusinessException(final String message, final Set<String> errors, final Throwable cause) {
super(message, cause);
this.errors = errors;
}
public BusinessException(final String message, final Set<String> errors) {
super(message);
this.errors = errors;
}
public BusinessException(final Throwable cause) {
super(cause);
}
private Set<String> errors = new HashSet<String>();
public Set<String> getErrors() {
return errors;
}
}
......@@ -27,7 +27,7 @@ public class ChoreographyInstanceTO extends AbstractBaseBean {
private Long id;
private String name;
private Long choreographyInstanceId;
private String description;
......@@ -42,12 +42,12 @@ public class ChoreographyInstanceTO extends AbstractBaseBean {
this.id = id;
}
public String getName() {
return name;
public Long getChoreographyInstanceId() {
return choreographyInstanceId;
}
public void setName(final String name) {
this.name = name;
public void setChoreographyInstanceId(final Long choreographyInstanceId) {
this.choreographyInstanceId = choreographyInstanceId;
}
public String getDescription() {
......@@ -58,7 +58,7 @@ public class ChoreographyInstanceTO extends AbstractBaseBean {
this.description = description;
}
public long getChoreographyId() {
public Long getChoreographyId() {
return choreographyId;
}
......
......@@ -15,6 +15,7 @@
*/
package eu.chorevolution.idm.common.to;
import eu.chorevolution.idm.common.types.ImageType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.syncope.common.lib.AbstractBaseBean;
......@@ -33,11 +34,11 @@ public class ChoreographyTO extends AbstractBaseBean {
private byte[] diagram;
private byte[] messageType;
private byte[] messageTypes;
private byte[] image;
private String imageType;
private ImageType imageType;
public Long getId() {
return id;
......@@ -71,12 +72,12 @@ public class ChoreographyTO extends AbstractBaseBean {
this.diagram = diagram;
}
public byte[] getMessageType() {
return messageType;
public byte[] getMessageTypes() {
return messageTypes;
}
public void setMessageType(final byte[] messageType) {
this.messageType = messageType;
public void setMessageTypes(final byte[] messageTypes) {
this.messageTypes = messageTypes;
}
public byte[] getImage() {
......@@ -87,13 +88,12 @@ public class ChoreographyTO extends AbstractBaseBean {
this.image = image;
}
public String getImageType() {
public ImageType getImageType() {
return imageType;
}
public void setImageType(final String imageType) {
public void setImageType(final ImageType imageType) {
this.imageType = imageType;
}
}
......@@ -19,7 +19,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.syncope.common.lib.AbstractBaseBean;
@XmlRootElement(name = "coordinationDelegate")
@XmlRootElement(name = "coordination_delegate")
@XmlType
public class CoordinationDelegateTO extends AbstractBaseBean {
......
......@@ -15,17 +15,23 @@
*/
package eu.chorevolution.idm.common.to;
import eu.chorevolution.idm.common.types.ArtifactType;
import eu.chorevolution.idm.common.types.EventType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.syncope.common.lib.AbstractBaseBean;
@XmlRootElement(name = "event_data")
@XmlType
public class EventDataTO extends AbstractBaseBean {
private static final long serialVersionUID = 3482017510413664039L;
private String choreographyName;
private String choreographyInstance;
private Long choreographyInstanceId;
private String artifactType;
private ArtifactType artifactType;
private String artifactRole;
......@@ -35,18 +41,13 @@ public class EventDataTO extends AbstractBaseBean {
private String targetState;
private String targetArtifactName;
private String operation;
public enum EventType {
RECEIVING_REQUEST, FORWARDING_REQUEST, RECEIVING_RESPONSE, FORWARDING_RESPONSE, SEND_NOTIFY, SEND_UPDATE,
WAIT_BEFORE, WAIT_AFTER, SENDING_REQUEST, REPLY_RESPONSE
}
private EventType eventType;
private long timestamp;
private String targetArtifactName;
private long eventTimestamp;
public String getChoreographyName() {
return choreographyName;
......@@ -56,19 +57,19 @@ public class EventDataTO extends AbstractBaseBean {
this.choreographyName = choreographyName;
}
public String getChoreographyInstance() {
return choreographyInstance;
public Long getChoreographyInstanceId() {
return choreographyInstanceId;
}
public void setChoreographyInstance(final String choreographyInstance) {
this.choreographyInstance = choreographyInstance;
public void setChoreographyInstanceId(final Long choreographyInstanceId) {
this.choreographyInstanceId = choreographyInstanceId;
}
public String getArtifactType() {
public ArtifactType getArtifactType() {
return artifactType;
}
public void setArtifactType(final String artifactType) {
public void setArtifactType(final ArtifactType artifactType) {
this.artifactType = artifactType;
}
......@@ -128,12 +129,12 @@ public class EventDataTO extends AbstractBaseBean {
this.eventType = eventType;
}
public long getTimestamp() {
return timestamp;
public long getEventTimestamp() {
return eventTimestamp;
}
public void setTimestamp(final long timestamp) {
this.timestamp = timestamp;
public void setEventTimestamp(final long eventTimestamp) {
this.eventTimestamp = eventTimestamp;
}
......
......@@ -13,24 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.syncope.core.persistence.api.dao;
package eu.chorevolution.idm.common.types;
import java.util.List;
import org.apache.syncope.core.persistence.api.entity.Instance;
public enum ArtifactType {
public interface InstanceDAO extends DAO<Instance, Long> {
List<Instance> findAll();
List<Instance> findByChoreography(Long choreographyId);
Instance findById(Long id);
Instance findByName(Long choreographyId, String name);
void save(Instance e);
void delete(Instance e);
void deleteAll();
CD,
SERVICE
}
/*
* Copyright 2016 The CHOReVOLUTION project.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.chorevolution.idm.common.types;
public enum EventType {
SENDING_REQUEST,
RECEIVING_REQUEST,
FORWARDING_REQUEST,
REPLY_RESPONSE,
RECEIVING_RESPONSE,
FORWARDING_RESPONSE,
SEND_NOTIFY,
SEND_UPDATE,
WAIT_BEFORE,
WAIT_AFTER
}
......@@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.syncope.core.persistence.api.entity;
package eu.chorevolution.idm.common.types;
public interface Instance extends Entity<Long> {
public enum ImageType {
String getName();
JPEG(".jpg"),
PNG(".png"),
BMP(".bmp");
void setName(String name);
String getDescription();
void setDestription(String description);
Long getChoreogrpahyId();
void setChoreographyId(Long choreographyId);
private String extension;
ImageType(final String extension) {
this.extension = extension;
}
public String getExtension() {
return this.extension;
}
}
......@@ -15,25 +15,27 @@
*/
package org.apache.syncope.core.logic;
import eu.chorevolution.idm.common.BusinessException;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.EventDataTO;
import java.lang.reflect.Method;
import java.util.List;
import org.apache.syncope.common.lib.AbstractBaseBean;
import org.apache.syncope.core.persistence.api.dao.ChoreographyDAO;
import org.apache.syncope.core.persistence.api.dao.EventDAO;
import org.apache.syncope.core.persistence.api.dao.InstanceDAO;
import org.apache.syncope.core.persistence.api.entity.Choreography;
import org.apache.syncope.core.persistence.api.entity.Event;
import org.apache.syncope.core.persistence.api.entity.Instance;
import org.apache.syncope.core.persistence.jpa.entity.JPAChoreography;
import org.apache.syncope.core.persistence.jpa.entity.JPAEvent;
import org.apache.syncope.core.persistence.jpa.entity.JPAInstance;
import org.apache.syncope.core.persistence.jpa.entity.JPAChoreographyInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.apache.syncope.core.persistence.api.entity.ChoreographyInstance;
import org.apache.syncope.core.persistence.api.dao.ChoreographyInstanceDAO;
import org.apache.syncope.core.persistence.jpa.entity.JPAChoreography;
@Component
public class CollectorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
@Override
protected AbstractBaseBean resolveReference(final Method method, final Object... os)
throws UnresolvedReferenceException {
......@@ -44,51 +46,37 @@ public class CollectorLogic extends AbstractTransactionalLogic<AbstractBaseBean>
private EventDAO eventDAO;
@Autowired
private InstanceDAO instanceDAO;
private ChoreographyInstanceDAO choreographyInstanceDAO;
@Autowired
private ChoreographyDAO choreographyDAO;
public void saveLogEvent(final EventDataTO data) throws BusinessException {
public void saveLogEvent(final EventDataTO data) {
//1) Check whether choreography exists into database, add new one if not
//Check whether instance of given choreography exists, add new one if not
ChoreographyInstance choreographyInstance = choreographyInstanceDAO.findByChoreographyInstanceId(
data.getChoreographyName(), data.getChoreographyInstanceId()
);
String choreographyName = data.getChoreographyName();
Choreography chor = choreographyDAO.find(choreographyName);
if (choreographyInstance == null) {
Choreography choreography = choreographyDAO.findByName(data.getChoreographyName());
Long choreographyKey;
if (choreography == null) {
throw new BusinessException("Cannot find choreography");
}
if (chor != null) {
choreographyKey = chor.getKey();
} else {
chor = new JPAChoreography();
chor.setName(choreographyName);
chor.setDescription("No description available");
choreographyDAO.save(chor);
choreographyKey = chor.getKey();
}
choreographyInstance = new JPAChoreographyInstance();
choreographyInstance.setChoreography(choreography);
choreographyInstance.setChoreographyInstanceId(data.getChoreographyInstanceId());
choreographyInstance.setDestription("No description available");
//2) Check whether instance of given choreography exists, add new one if not
choreography.addChoreographyInstance(choreographyInstance);
String instanceName = data.getChoreographyInstance();
Instance in = instanceDAO.findByName(choreographyKey, instanceName);
Long instanceKey;
if (in != null) {
instanceKey = in.getKey();
} else {
in = new JPAInstance();
in.setChoreographyId(choreographyKey);
in.setName(instanceName);
in.setDestription("No description available");
instanceDAO.save(in);
instanceKey = in.getKey();
choreographyInstanceDAO.save(choreographyInstance);
}
//3) Log event
//Log event
Event event = new JPAEvent();
event.setArtifactName(data.getArtifactName());
event.setArtifactRole(data.getArtifactRole());
......@@ -96,34 +84,54 @@ public class CollectorLogic extends AbstractTransactionalLogic<AbstractBaseBean>
event.setOperation(data.getOperation());
event.setSourceState(data.getSourceState());
event.setTargetState(data.getTargetState());
event.setTimestamp(data.getTimestamp());
event.setType(data.getEventType().toString());
event.setInstanceId(instanceKey);
event.setEventTimestamp(data.getEventTimestamp());
event.setEventType(data.getEventType());
choreographyInstance.addEvent(event);
eventDAO.save(event);
}
public void addChoreography(final ChoreographyTO data) {
Choreography choreography = new JPAChoreography();
choreography.setName(data.getName());
choreography.setDescription(data.getDescription());
choreography.setDiagram(data.getDiagram());
choreography.setImage(data.getImage());
choreography.setImageType(data.getImageType());
choreography.setMessageTypes(data.getMessageTypes());
choreographyDAO.save(choreography);
}
//TODO remove this method
public String getDatabase() {
List<Choreography> chors = choreographyDAO.findAll();
List<Instance> ins = instanceDAO.findAll();
List<ChoreographyInstance> ins = choreographyInstanceDAO.findAll();
List<Event> es = eventDAO.findAll();
String r = "CHOREOGRAPHIES:\n";
for (Choreography current : chors) {
r = r + "->" + current.getKey() + "\t" + current.getName() + "\t" + current.getDescription() + "\n";
r = r + "-> ID: " + current.getKey() + "\t" + current.getName() + "\t" + current.getDescription() + "\n";
}
r = r + "\nINSTANCES:\n";
for (Instance current : ins) {
r = r + "->" + current.getKey() + "\tC:" + current.getChoreogrpahyId()
+ "\t" + current.getName() + "\t" + current.getDescription() + "\n";
for (ChoreographyInstance current : ins) {
r = r + "-> ID: " + current.getKey() + "\tChoreography ID: " + current.getChoreography().getId()
+ "\tInstance: " + current.getChoreographyInstanceId()
+ "\tDescription: " + current.getDescription() + "\n";
}
r = r + "\nEVENTS:\n";
for (Event current : es) {
r = r + "->" + current.getKey() + "\tI:" + current.getInstanceId()
r = r + "-> ID: " + current.getKey() + "\tInstance ID: " + current.getChoreographyInstance().getId()
+ "\t" + current.getArtifactName() + "\t" + current.getOperation()
+ "\t" + current.getType() + "\t" + current.getTimestamp() + "\n";
+ "\t" + current.getEventType() + "\t" + current.getEventTimestamp() + "\n";
}
return r;
......
......@@ -22,15 +22,17 @@ import java.lang.reflect.Method;
import java.util.List;
import org.apache.syncope.common.lib.AbstractBaseBean;
import eu.chorevolution.idm.common.to.OperationDataTO;
import eu.chorevolution.idm.common.types.ArtifactType;
import eu.chorevolution.idm.common.types.EventType;
import java.util.LinkedList;
import org.apache.syncope.core.persistence.api.dao.ChoreographyDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.apache.syncope.core.persistence.api.dao.EventDAO;
import org.apache.syncope.core.persistence.api.dao.InstanceDAO;
import org.apache.syncope.core.persistence.api.entity.Choreography;
import org.apache.syncope.core.persistence.api.entity.Event;
import org.apache.syncope.core.persistence.api.entity.Instance;
import org.apache.syncope.core.persistence.api.entity.ChoreographyInstance;
import org.apache.syncope.core.persistence.api.dao.ChoreographyInstanceDAO;
@Component
public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
......@@ -39,7 +41,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
private ChoreographyDAO choreographyDAO;
@Autowired
private InstanceDAO instanceDAO;
private ChoreographyInstanceDAO choreographyInstanceDAO;
@Autowired
private EventDAO eventDAO;
......@@ -81,14 +83,15 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {