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

Added implementation for DAO queries and aligned logic

parent 1cef98de
......@@ -52,7 +52,8 @@ limitations under the License.
<artifactId>syncope-ext-choreography-common-lib</artifactId>
<version>${project.version}</version>
</dependency>
<!--<dependency>
<!--
<dependency>
<groupId>org.apache.syncope.ext.choreography</groupId>
<artifactId>syncope-ext-choreography-persistence-jpa</artifactId>
<version>${project.version}</version>
......
......@@ -29,12 +29,18 @@ 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 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;
......@@ -61,23 +67,29 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
public List<ChoreographyTO> choreographyList() {
List<ChoreographyTO> result = new ArrayList<>();
ChoreographyTO to = new ChoreographyTO();
ChoreographyTO to;
/*
* Logic for retreive list of choreographies from DB
* Logic for retreive list of choreographies without DAO function
StartRequestDAO dao = new JPAStartRequestDAO();
List<String> availableRequests = dao.findChoreographiesNames();
List<ChoreographyTO> availableChoreographies = new ArrayList<>();
List<StartRequest> availableRequests = dao.findAll();
Set<String> choreographyNames = new LinkedHashSet<>();
for (String currentName: availableRequests) {
to.setName(currentName);
for (StartRequest currentRequest : availableRequests) {
choreographyNames.add(currentRequest.getChoreographyName());
}
for (String currentChoreography : choreographyNames) {
to = new ChoreographyTO();
to.setName(currentChoreography);
to.setDescription("No description available");
availableChoreographies.add(to);
result.add(to);
}
return availableChoreographies;
*/
to = new ChoreographyTO();
//to.setKey(1);
to.setDescription("Description of choreography 1");
to.setName("Choreography 1");
......@@ -108,30 +120,36 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
* This method returns a list of all instances of given choreography
*
* @param choreographyName
* @param chor
* @return List<ChoreographyInstanceTO>
* @return CoordinationDelegateTO list
*/
public List<ChoreographyInstanceTO> instanceList(final String choreographyName) {
List<ChoreographyInstanceTO> result = new ArrayList<>();
ChoreographyInstanceTO to = new ChoreographyInstanceTO();
ChoreographyInstanceTO to;
/*
* Logic for retreive list of choreographies from DB
* Logic for retrieve list of choreography instances without DAO functions
StartRequestDAO dao = new JPAStartRequestDAO();
List<String> availableInstances = dao.findChoreographyInstances("");
List<StartRequest> availableRequests = dao.findAll();
Set<String> instanceNames = new LinkedHashSet<>();
for (String currentInstanceName: availableInstances) {
to.setChoreographyKey(1);
to.setDescription("No description available");
to.setKey(1);
for (StartRequest currentRequest : availableRequests) {
if (currentRequest.getChoreographyName().equals(choreographyName)) {
instanceNames.add(currentRequest.getInstanceName());
}
}
for (String currentInstanceName : instanceNames) {
to = new ChoreographyInstanceTO();
to.setChoreographyName(choreographyName);
to.setName(currentInstanceName);
result.add(to);
}
return availableInstances;
*/
*/
to = new ChoreographyInstanceTO();
to.setChoreographyName(choreographyName);
to.setName("Instance 1");
to.setDescription("No description available");
......@@ -160,29 +178,46 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
*
* @param choreographyName
* @param instanceName
* @return List<CoordinationDelegateTO>
* @return CoordinationDelegateTO list
*/
public List<CoordinationDelegateTO> cdList(final String choreographyName, final String instanceName) {
List<CoordinationDelegateTO> coordinationDelegates = new ArrayList<>();
CoordinationDelegateTO to = new CoordinationDelegateTO();
CoordinationDelegateTO to;
/*
StartRequestDAO dao = new JPAStartRequestDAO();
List<String> cds = dao.findCds(choreographyName, instanceName);
List<StartRequest> availableRequests = dao.findAll();
ForwardRequestDAO forwardReqDao = new JPAForwardRequestDAO();
ForwardResponseDAO forwardResDao = new JPAForwardResponseDAO();
EndRequestDAO endReqDao = new JPAEndRequestDAO();
NumberCoordMessageDAO numDao = new JPANumberCoordMessageDAO();
for (String cdName : cds) {
Set<String> availableCds = new LinkedHashSet<>();
for (StartRequest currentRequest : availableRequests) {
if (currentRequest.getChoreographyName().equals(choreographyName) &&
currentRequest.getInstanceName().equals(instanceName)) {
availableCds.add(currentRequest.getCdName());
}
}
for (String cdName : availableCds) {
to = new CoordinationDelegateTO();
to.setName(cdName);
to.setChoreographyInstanceName(instanceName);
to.setChoreographyName(choreographyName);
List<String> operations = dao.findCdOperations(choreographyName, instanceName, cdName);
Set<String> operations = new LinkedHashSet<>();
for (StartRequest currentRequest : availableRequests) {
if (currentRequest.getChoreographyName().equals(choreographyName) &&
currentRequest.getInstanceName().equals(instanceName) &&
currentRequest.getCdName().equals(cdName)) {
operations.add(currentRequest.getOperationName());
}
}
int opNumber = 0, messageNumber = 0;
long overhead = 0, executionTime = 0;
......@@ -210,6 +245,7 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
coordinationDelegates.add(to);
}*/
to = new CoordinationDelegateTO();
//to.setKey(1);
to.setName("CD 1");
to.setChoreographyInstanceName(instanceName);
......
......@@ -24,7 +24,7 @@ public interface EndRequestDAO extends DAO<EndRequest, Long> {
List<EndRequest> findAll();
EndRequest save(EndRequest response);
void save(EndRequest request);
void delete(String key);
}
......@@ -24,7 +24,7 @@ public interface ForwardRequestDAO extends DAO<ForwardRequest, Long> {
List<ForwardRequest> findAll();
ForwardRequest save(ForwardRequest request);
void save(ForwardRequest request);
void delete(String key);
}
......@@ -24,7 +24,7 @@ public interface ForwardResponseDAO extends DAO<ForwardResponse, Long> {
List<ForwardResponse> findAll();
ForwardResponse save(ForwardResponse response);
void save(ForwardResponse response);
void delete(String key);
}
......@@ -24,7 +24,7 @@ public interface NumberCoordMessageDAO extends DAO<NumberCoordMessage, Long> {
List<NumberCoordMessage> findAll();
NumberCoordMessage save(NumberCoordMessage response);
void save(NumberCoordMessage messages);
void delete(String key);
}
......@@ -22,17 +22,9 @@ public interface StartRequestDAO extends DAO<StartRequest, Long> {
StartRequest find(String cdName, String operationName, String instanceName, String choreographyName);
List<String> findChoreographiesNames();
List<String> findChoreographyInstances(String choreographyName);
List<String> findCdOperations(String choreographyName, String instanceName, String cdName);
List<String> findCds(String choreographyName, String instanceName);
List<StartRequest> findAll();
StartRequest save(StartRequest request);
void save(StartRequest request);
void delete(String key);
}
......@@ -16,25 +16,41 @@
package org.apache.syncope.core.persistence.jpa.dao;
import java.util.List;
import javax.persistence.TypedQuery;
import org.apache.syncope.core.persistence.api.dao.EndRequestDAO;
import org.apache.syncope.core.persistence.api.entity.EndRequest;
import org.apache.syncope.core.persistence.jpa.entity.JPAEndRequest;
public class JPAEndRequestDAO extends AbstractDAO<EndRequest, Long> implements EndRequestDAO {
@Override
public EndRequest find(final String cdName, final String operationName, final String instanceName,
final String choreographyName) {
return null;
TypedQuery<EndRequest> query = entityManager().createQuery(
"SELECT e FROM" + JPAEndRequest.class.getSimpleName()
+ " e WHERE e.cdName = :cdName AND e.operationName = :operationName"
+ " AND e.instanceName = :instanceName AND e.choreographyName :choreographyName",
EndRequest.class);
query.setParameter("cdName", cdName);
query.setParameter("operationName", operationName);
query.setParameter("instanceName", instanceName);
query.setParameter("choreographyName", choreographyName);
return query.getSingleResult();
}
@Override
public List<EndRequest> findAll() {
return null;
TypedQuery<EndRequest> query = entityManager().createQuery(
"SELECT e FROM " + JPAEndRequest.class.getSimpleName() + " e ", EndRequest.class);
return query.getResultList();
}
@Override
public EndRequest save(final EndRequest response) {
return null;
public void save(final EndRequest request) {
entityManager().persist(request);
}
@Override
......
......@@ -16,25 +16,41 @@
package org.apache.syncope.core.persistence.jpa.dao;
import java.util.List;
import javax.persistence.TypedQuery;
import org.apache.syncope.core.persistence.api.dao.ForwardRequestDAO;
import org.apache.syncope.core.persistence.api.entity.ForwardRequest;
import org.apache.syncope.core.persistence.jpa.entity.JPAForwardRequest;
public class JPAForwardRequestDAO extends AbstractDAO<ForwardRequest, Long> implements ForwardRequestDAO {
@Override
public ForwardRequest find(final String cdName, final String operationName, final String instanceName,
final String choreographyName) {
return null;
TypedQuery<ForwardRequest> query = entityManager().createQuery(
"SELECT e FROM" + JPAForwardRequest.class.getSimpleName()
+ " e WHERE e.cdName = :cdName AND e.operationName = :operationName"
+ " AND e.instanceName = :instanceName AND e.choreographyName :choreographyName",
ForwardRequest.class);
query.setParameter("cdName", cdName);
query.setParameter("operationName", operationName);
query.setParameter("instanceName", instanceName);
query.setParameter("choreographyName", choreographyName);
return query.getSingleResult();
}
@Override
public List<ForwardRequest> findAll() {
return null;
TypedQuery<ForwardRequest> query = entityManager().createQuery(
"SELECT e FROM " + JPAForwardRequest.class.getSimpleName() + " e ", ForwardRequest.class);
return query.getResultList();
}
@Override
public ForwardRequest save(final ForwardRequest request) {
return null;
public void save(final ForwardRequest request) {
entityManager().persist(request);
}
@Override
......
......@@ -16,25 +16,41 @@
package org.apache.syncope.core.persistence.jpa.dao;
import java.util.List;
import javax.persistence.TypedQuery;
import org.apache.syncope.core.persistence.api.dao.ForwardResponseDAO;
import org.apache.syncope.core.persistence.api.entity.ForwardResponse;
import org.apache.syncope.core.persistence.jpa.entity.JPAForwardResponse;
public class JPAForwardResponseDAO extends AbstractDAO<ForwardResponse, Long> implements ForwardResponseDAO {
@Override
public ForwardResponse find(final String cdName, final String operationName, final String instanceName,
final String choreographyName) {
return null;
TypedQuery<ForwardResponse> query = entityManager().createQuery(
"SELECT e FROM" + JPAForwardResponse.class.getSimpleName()
+ " e WHERE e.cdName = :cdName AND e.operationName = :operationName"
+ " AND e.instanceName = :instanceName AND e.choreographyName :choreographyName",
ForwardResponse.class);
query.setParameter("cdName", cdName);
query.setParameter("operationName", operationName);
query.setParameter("instanceName", instanceName);
query.setParameter("choreographyName", choreographyName);
return query.getSingleResult();
}
@Override
public List<ForwardResponse> findAll() {
return null;
TypedQuery<ForwardResponse> query = entityManager().createQuery(
"SELECT e FROM " + JPAForwardResponse.class.getSimpleName() + " e ", ForwardResponse.class);
return query.getResultList();
}
@Override
public ForwardResponse save(final ForwardResponse response) {
return null;
public void save(final ForwardResponse response) {
entityManager().persist(response);
}
@Override
......
......@@ -16,8 +16,10 @@
package org.apache.syncope.core.persistence.jpa.dao;
import java.util.List;
import javax.persistence.TypedQuery;
import org.apache.syncope.core.persistence.api.dao.NumberCoordMessageDAO;
import org.apache.syncope.core.persistence.api.entity.NumberCoordMessage;
import org.apache.syncope.core.persistence.jpa.entity.JPANumberCoordMessage;
public class JPANumberCoordMessageDAO extends AbstractDAO<NumberCoordMessage, Long>
implements NumberCoordMessageDAO {
......@@ -25,17 +27,31 @@ public class JPANumberCoordMessageDAO extends AbstractDAO<NumberCoordMessage, Lo
@Override
public NumberCoordMessage find(final String cdName, final String operationName, final String instanceName,
final String choreographyName) {
return null;
TypedQuery<NumberCoordMessage> query = entityManager().createQuery(
"SELECT e FROM" + JPANumberCoordMessage.class.getSimpleName()
+ " e WHERE e.cdName = :cdName AND e.operationName = :operationName"
+ " AND e.instanceName = :instanceName AND e.choreographyName :choreographyName",
NumberCoordMessage.class);
query.setParameter("cdName", cdName);
query.setParameter("operationName", operationName);
query.setParameter("instanceName", instanceName);
query.setParameter("choreographyName", choreographyName);
return query.getSingleResult();
}
@Override
public List<NumberCoordMessage> findAll() {
return null;
TypedQuery<NumberCoordMessage> query = entityManager().createQuery(
"SELECT e FROM " + JPANumberCoordMessage.class.getSimpleName() + " e ", NumberCoordMessage.class);
return query.getResultList();
}
@Override
public NumberCoordMessage save(final NumberCoordMessage response) {
return null;
public void save(final NumberCoordMessage messages) {
entityManager().persist(messages);
}
@Override
......
......@@ -28,7 +28,19 @@ public class JPAStartRequestDAO extends AbstractDAO<StartRequest, Long> implemen
final String operationName,
final String instanceName,
final String choreographyName) {
return null;
TypedQuery<StartRequest> query = entityManager().createQuery(
"SELECT e FROM" + JPAStartRequest.class.getSimpleName()
+ " e WHERE e.cdName = :cdName AND e.operationName = :operationName"
+ " AND e.instanceName = :instanceName AND e.choreographyName :choreographyName",
StartRequest.class);
query.setParameter("cdName", cdName);
query.setParameter("operationName", operationName);
query.setParameter("instanceName", instanceName);
query.setParameter("choreographyName", choreographyName);
return query.getSingleResult();
}
@Override
......@@ -39,34 +51,11 @@ public class JPAStartRequestDAO extends AbstractDAO<StartRequest, Long> implemen
}
@Override
public StartRequest save(final StartRequest request) {
return null;
public void save(final StartRequest request) {
entityManager().persist(request);
}
@Override
public void delete(final String key) {
}
@Override
public List<String> findChoreographiesNames() {
return null;
}
@Override
public List<String> findChoreographyInstances(final String choreographyName) {
return null;
}
@Override
public List<String> findCdOperations(final String choreographyName,
final String instanceName,
final String cdName) {
return null;
}
@Override
public List<String> findCds(final String choreographyName, final String instanceName) {
return null;
}
}
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