Commit 9c565144 authored by Gianluca Filippone's avatar Gianluca Filippone
Browse files

Resolved persistence problem

parent 34a18c91
......@@ -27,30 +27,45 @@ import eu.choreovolution.idm.common.to.ForwardRequestTO;
import eu.choreovolution.idm.common.to.ForwardResponseTO;
import eu.choreovolution.idm.common.to.NumberCoordMessageTO;
import eu.choreovolution.idm.common.to.StartRequestTO;
//import java.util.LinkedHashSet;
//import java.util.Set;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.syncope.core.persistence.api.dao.EndRequestDAO;
import org.apache.syncope.core.persistence.api.dao.ForwardRequestDAO;
import org.apache.syncope.core.persistence.api.dao.ForwardResponseDAO;
import org.apache.syncope.core.persistence.api.dao.NumberCoordMessageDAO;
import org.apache.syncope.core.persistence.api.dao.StartRequestDAO;
import org.apache.syncope.core.persistence.api.entity.EndRequest;
import org.apache.syncope.core.persistence.api.entity.ForwardRequest;
import org.apache.syncope.core.persistence.api.entity.ForwardResponse;
import org.apache.syncope.core.persistence.api.entity.NumberCoordMessage;
import org.apache.syncope.core.persistence.api.entity.StartRequest;
import org.apache.syncope.core.persistence.api.entity.TimeData;
import org.apache.syncope.core.persistence.jpa.dao.JPAEndRequestDAO;
import org.apache.syncope.core.persistence.jpa.dao.JPAForwardRequestDAO;
import org.apache.syncope.core.persistence.jpa.dao.JPAForwardResponseDAO;
import org.apache.syncope.core.persistence.jpa.dao.JPANumberCoordMessageDAO;
import org.apache.syncope.core.persistence.jpa.dao.JPAStartRequestDAO;
import org.apache.syncope.core.persistence.jpa.entity.JPAEndRequest;
import org.apache.syncope.core.persistence.jpa.entity.JPAForwardRequest;
import org.apache.syncope.core.persistence.jpa.entity.JPAForwardResponse;
import org.apache.syncope.core.persistence.jpa.entity.JPANumberCoordMessage;
import org.apache.syncope.core.persistence.jpa.entity.JPAStartRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
@Autowired
private StartRequestDAO startRequestDAO;
@Autowired
private ForwardRequestDAO forwardRequestDAO;
@Autowired
private ForwardResponseDAO forwardResponseDAO;
@Autowired
private EndRequestDAO endRequestDAO;
@Autowired
private NumberCoordMessageDAO numberCoordMessageDAO;
@Override
protected AbstractBaseBean resolveReference(final Method method, final Object... args)
throws UnresolvedReferenceException {
......@@ -63,11 +78,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
ChoreographyTO to;
/*
* Logic for retreive list of choreographies without DAO function
StartRequestDAO dao = new JPAStartRequestDAO();
List<StartRequest> availableRequests = dao.findAll();
List<StartRequest> availableRequests = startRequestDAO.findAll();
Set<String> choreographyNames = new LinkedHashSet<>();
for (StartRequest currentRequest : availableRequests) {
......@@ -80,9 +91,8 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
to.setDescription("No description available");
result.add(to);
}
*/
/*
to = new ChoreographyTO();
//to.setKey(1);
to.setDescription("Description of choreography 1");
......@@ -105,7 +115,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
//to.setKey(4);
to.setDescription("Description of choreography 4");
to.setName("Choreography 4");
result.add(to);
result.add(to);*/
return result;
}
......@@ -121,12 +131,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
ChoreographyInstanceTO to;
/*
* Logic for retrieve list of choreography instances without DAO functions
StartRequestDAO dao = new JPAStartRequestDAO();
List<StartRequest> availableRequests = dao.findAll();
List<StartRequest> availableRequests = startRequestDAO.findAll();
Set<String> instanceNames = new LinkedHashSet<>();
for (StartRequest currentRequest : availableRequests) {
......@@ -139,10 +144,11 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
to = new ChoreographyInstanceTO();
to.setChoreographyName(choreographyName);
to.setName(currentInstanceName);
to.setDescription("No description available");
result.add(to);
}
*/
/*
to = new ChoreographyInstanceTO();
to.setChoreographyName(choreographyName);
to.setName("Instance 1");
......@@ -162,11 +168,11 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
to = new ChoreographyInstanceTO();
to.setName("Instance 4");
to.setDescription("No description available");
result.add(to);
result.add(to);*/
return result;
}
/**
* This method returns a list of CDs for a given choreography instance
*
......@@ -179,20 +185,13 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
CoordinationDelegateTO to;
/*
StartRequestDAO dao = new JPAStartRequestDAO();
List<StartRequest> availableRequests = dao.findAll();
ForwardRequestDAO forwardReqDao = new JPAForwardRequestDAO();
ForwardResponseDAO forwardResDao = new JPAForwardResponseDAO();
EndRequestDAO endReqDao = new JPAEndRequestDAO();
NumberCoordMessageDAO numDao = new JPANumberCoordMessageDAO();
List<StartRequest> availableRequests = startRequestDAO.findAll();
Set<String> availableCds = new LinkedHashSet<>();
for (StartRequest currentRequest : availableRequests) {
if (currentRequest.getChoreographyName().equals(choreographyName) &&
currentRequest.getInstanceName().equals(instanceName)) {
if (currentRequest.getChoreographyName().equals(choreographyName)
&& currentRequest.getInstanceName().equals(instanceName)) {
availableCds.add(currentRequest.getCdName());
}
}
......@@ -206,9 +205,9 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
Set<String> operations = new LinkedHashSet<>();
for (StartRequest currentRequest : availableRequests) {
if (currentRequest.getChoreographyName().equals(choreographyName) &&
currentRequest.getInstanceName().equals(instanceName) &&
currentRequest.getCdName().equals(cdName)) {
if (currentRequest.getChoreographyName().equals(choreographyName)
&& currentRequest.getInstanceName().equals(instanceName)
&& currentRequest.getCdName().equals(cdName)) {
operations.add(currentRequest.getOperationName());
}
}
......@@ -219,16 +218,17 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
for (String currentOp : operations) {
opNumber++;
StartRequest startReq = dao.find(cdName, currentOp, instanceName, choreographyName);
ForwardRequest forwardReq = forwardReqDao.find(cdName, currentOp, instanceName, choreographyName);
ForwardResponse forwardRes = forwardResDao.find(cdName, currentOp, instanceName, choreographyName);
EndRequest endReq = endReqDao.find(cdName, currentOp, instanceName, choreographyName);
NumberCoordMessage numMessages = numDao.find(cdName, currentOp, instanceName, choreographyName);
StartRequest startReq = startRequestDAO.find(cdName, currentOp, instanceName, choreographyName);
ForwardRequest forwardReq = forwardRequestDAO.find(cdName, currentOp, instanceName, choreographyName);
ForwardResponse forwardRes = forwardResponseDAO.find(cdName, currentOp, instanceName, choreographyName);
EndRequest endReq = endRequestDAO.find(cdName, currentOp, instanceName, choreographyName);
NumberCoordMessage numMessages = numberCoordMessageDAO.find(
cdName, currentOp, instanceName, choreographyName);
messageNumber = messageNumber + numMessages.getNumMessages();
overhead = overhead +
(forwardReq.getRecordTime() - startReq.getRecordTime()) +
(endReq.getRecordTime() - forwardRes.getRecordTime());
overhead = overhead
+ (forwardReq.getRecordTime() - startReq.getRecordTime())
+ (endReq.getRecordTime() - forwardRes.getRecordTime());
executionTime = executionTime + (endReq.getRecordTime() + startReq.getRecordTime());
}
......@@ -237,8 +237,8 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
to.setTotalOverhead(overhead);
to.setTotalExecutionTime(executionTime);
coordinationDelegates.add(to);
}*/
}
/*
to = new CoordinationDelegateTO();
//to.setKey(1);
to.setName("CD 1");
......@@ -292,7 +292,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
to.setSentMessages(2);
to.setTotalExecutionTime(20);
to.setTotalOverhead(14);
coordinationDelegates.add(to);
coordinationDelegates.add(to);*/
return coordinationDelegates;
}
......@@ -316,8 +316,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
requestEntity.setOperationName(startRequest.getOperationName());
requestEntity.setRecordTime(startRequest.getTimestamp());
StartRequestDAO startDao = new JPAStartRequestDAO();
startDao.save((JPAStartRequest) requestEntity);
startRequestDAO.save((JPAStartRequest) requestEntity);
break;
case "forward_request":
......@@ -329,8 +328,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
requestEntity.setOperationName(forwardRequest.getOperationName());
requestEntity.setRecordTime(forwardRequest.getTimestamp());
ForwardRequestDAO forwardRequestDao = new JPAForwardRequestDAO();
forwardRequestDao.save((JPAForwardRequest) requestEntity);
forwardRequestDAO.save((JPAForwardRequest) requestEntity);
break;
case "forward_response":
......@@ -342,8 +340,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
requestEntity.setOperationName(forwardResponse.getOperationName());
requestEntity.setRecordTime(forwardResponse.getTimestamp());
ForwardResponseDAO forwardResponseDao = new JPAForwardResponseDAO();
forwardResponseDao.save((JPAForwardResponse) requestEntity);
forwardResponseDAO.save((JPAForwardResponse) requestEntity);
break;
case "end_request":
......@@ -355,8 +352,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
requestEntity.setOperationName(endRequest.getOperationName());
requestEntity.setRecordTime(endRequest.getTimestamp());
EndRequestDAO endRequestDao = new JPAEndRequestDAO();
endRequestDao.save((JPAEndRequest) requestEntity);
endRequestDAO.save((JPAEndRequest) requestEntity);
break;
default:
break;
......@@ -371,7 +367,22 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
requestEntity.setOperationName(data.getOperationName());
requestEntity.setNumMessages(data.getMessageNumber());
NumberCoordMessageDAO dao = new JPANumberCoordMessageDAO();
dao.save(requestEntity);
numberCoordMessageDAO.save(requestEntity);
}
/* public StartRequest testMethod(final StartRequestTO data) {
// StartRequest request = new JPAStartRequest();
// request.setCdName(data.getCdName());
// request.setChoreographyName(data.getChoreographyName());
// request.setInstanceName(data.getInstanceName());
// request.setOperationName(data.toString());
// request.setRecordTime(data.getTimestamp());
// StartRequest ciao = startRequestDAO.find(
// data.getCdName(), data.getOperationName(), "Saved", data.getChoreographyName());
List<StartRequest> list = startRequestDAO.findAll();
StartRequest ciao = list.get(0);
//data.setInstanceName("Saved");
return ciao;
}*/
}
......@@ -41,7 +41,6 @@ under the License.
<dependency>
<groupId>org.apache.syncope.core</groupId>
<artifactId>syncope-core-persistence-jpa</artifactId>
<version>${syncope.version}</version>
</dependency>
<dependency>
<groupId>org.apache.syncope.ext.choreography</groupId>
......@@ -92,7 +91,7 @@ under the License.
<testResources>
<testResource>
<directory>${rootpom.basedir}/core/persistence-jpa/src/main/resources</directory>
<directory>${rootpom.basedir}/core/src/main/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
......
......@@ -15,6 +15,41 @@
*/
package org.apache.syncope.core.persistence.jpa.entity;
public class JPAChoreographyEntityFactory {
import org.apache.syncope.core.persistence.api.entity.ChoreographyEntityFactory;
import org.apache.syncope.core.persistence.api.entity.EndRequest;
import org.apache.syncope.core.persistence.api.entity.ForwardRequest;
import org.apache.syncope.core.persistence.api.entity.ForwardResponse;
import org.apache.syncope.core.persistence.api.entity.NumberCoordMessage;
import org.apache.syncope.core.persistence.api.entity.StartRequest;
import org.springframework.stereotype.Component;
@Component
public class JPAChoreographyEntityFactory implements ChoreographyEntityFactory {
@Override
public StartRequest newStartRequest() {
return new JPAStartRequest();
}
@Override
public ForwardRequest newForwardRequest() {
return new JPAForwardRequest();
}
@Override
public ForwardResponse newForwardResponse() {
return new JPAForwardResponse();
}
@Override
public EndRequest newEndRequest() {
return new JPAEndRequest();
}
@Override
public NumberCoordMessage newNumberCoordMessage() {
return new JPANumberCoordMessage();
}
}
......@@ -89,11 +89,11 @@ public interface CollectorService extends JAXRSService {
* @param request
* @return response
*/
@Path("test")
/* @Path("test")
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON})
Response testMethod(@NotNull StartRequestTO request);
Response testMethod(@NotNull StartRequestTO request);*/
// localhost:9080/syncope/rest/collector/test/?
// obj={"choreographyName":"Choreografia di prova","instanceName":"Istanza di prova",
......
......@@ -23,10 +23,7 @@ import eu.choreovolution.idm.common.to.NumberCoordMessageTO;
import eu.choreovolution.idm.common.to.StartRequestTO;
import org.apache.syncope.common.rest.api.service.CollectorService;
import org.apache.syncope.core.logic.MonitorLogic;
import org.apache.syncope.core.persistence.api.dao.StartRequestDAO;
import org.apache.syncope.core.persistence.api.entity.StartRequest;
import org.apache.syncope.core.persistence.jpa.dao.JPAStartRequestDAO;
import org.apache.syncope.core.persistence.jpa.entity.JPAStartRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -64,34 +61,11 @@ public class CollectorServiceImpl extends AbstractServiceImpl implements Collect
/*
* This is a test method
*/
@Override
/*@Override
public Response testMethod(final StartRequestTO data) {
/*StartRequestTO response;
if (data != null) {
response = data;
response.setTimestamp(1001);
} else {
response = new StartRequestTO();
response.setCdName("CD di prova");
response.setChoreographyName("Choreografia di prova");
response.setInstanceName("Istanza di prova");
response.setOperationName("Operazione di prova");
response.setTimestamp(1000);
}*/
StartRequest response = logic.testMethod(data);
StartRequestDAO dao = new JPAStartRequestDAO();
StartRequest request = new JPAStartRequest();
request.setCdName(data.getCdName());
request.setChoreographyName(data.getChoreographyName());
request.setInstanceName(data.getInstanceName());
request.setOperationName(data.toString());
request.setRecordTime(data.getTimestamp());
dao.save(request);
data.setInstanceName("Saved");
return Response.ok(data).build();
}
return Response.ok(response).build();
}*/
}
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