From: <pka...@us...> - 2009-07-27 22:09:24
|
Revision: 380 http://cse-ip.svn.sourceforge.net/cse-ip/?rev=380&view=rev Author: pkasprzak Date: 2009-07-27 22:09:18 +0000 (Mon, 27 Jul 2009) Log Message: ----------- * Stuff :) Modified Paths: -------------- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyManager.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyManagerImpl.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Entity.java Added Paths: ----------- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManager.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManagerImpl.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManagerRemote.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Dependency.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/DependencyStatus.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/WaitingProcess.java Removed Paths: ------------- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/Dependency.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyStatus.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyType.java Deleted: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/Dependency.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/Dependency.java 2009-07-27 22:07:54 UTC (rev 379) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/Dependency.java 2009-07-27 22:09:18 UTC (rev 380) @@ -1,93 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package de.campussource.cse.core; - -import java.io.Serializable; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -/** - * - * - * @author pete - */ -@Entity -public class Dependency implements Serializable { - - private static final long serialVersionUID = 1L; - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; - - /* ObjectId (= BPEL ProcessId) */ - private Long objectId; - - /* Dependency-Type */ - private DependencyType type; - - /* Dependency-Status */ - private DependencyStatus status; - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set - if (!(object instanceof Dependency)) { - return false; - } - Dependency other = (Dependency) object; - if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { - return false; - } - return true; - } - - @Override - public String toString() { - return "de.campussource.cse.core.Dependency[id=" + id + "]"; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Long getObjectId() { - return objectId; - } - - public void setObjectId(Long objectId) { - this.objectId = objectId; - } - - public DependencyStatus getStatus() { - return status; - } - - public void setStatus(DependencyStatus status) { - this.status = status; - } - - public DependencyType getType() { - return type; - } - - public void setType(DependencyType type) { - this.type = type; - } -} Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyManager.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyManager.java 2009-07-27 22:07:54 UTC (rev 379) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyManager.java 2009-07-27 22:09:18 UTC (rev 380) @@ -14,5 +14,7 @@ @Local public interface DependencyManager { - public void checkDependencies(int objectId, DependencyType dependencyType); + public void waitForDependencies(int entityId); + + public void satisfyDependencies(int entityId, String system); } Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyManagerImpl.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyManagerImpl.java 2009-07-27 22:07:54 UTC (rev 379) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyManagerImpl.java 2009-07-27 22:09:18 UTC (rev 380) @@ -1,13 +1,20 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - package de.campussource.cse.core; +import de.campussource.cse.core.pdm.Dependency; +import de.campussource.cse.core.pdm.DependencyStatus; +import de.campussource.cse.core.pdm.Entity; +import de.campussource.cse.core.pdm.EntityType; +import de.campussource.cse.core.pdm.Relation; +import de.campussource.cse.core.pdm.RelationType; +import de.campussource.cse.core.pdm.WaitingProcess; +import java.util.HashSet; +import java.util.List; +import java.util.logging.Logger; +import javax.ejb.EJB; import javax.ejb.Stateless; -import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import javax.xml.ws.WebServiceRef; +import org.netbeans.j2ee.wsdl.common.dependencymanagernotification.DependencyManagerNotificationService; /** * @@ -15,17 +22,177 @@ */ @Stateless(mappedName = "cse/DependencyManager") public class DependencyManagerImpl implements DependencyManagerRemote, DependencyManager { + @WebServiceRef(wsdlLocation = "META-INF/wsdl/client/DependencyManagerNotification/DependencyManagerNotification.wsdl") + private DependencyManagerNotificationService service; @PersistenceContext - private EntityManager em; + private javax.persistence.EntityManager em; - public void checkDependencies(int objectId, DependencyType dependencyType) { - throw new UnsupportedOperationException("Not supported yet."); + @EJB + private RelationManager relationManager; + + @EJB + private EntityManager entityManager; + + @EJB + private IdentityManager identityManager; + + @EJB + private SystemManager systemManager; + + private final static Logger logger = Logger.getLogger("de.campussource.cse.core.DependencyManager"); + + // ---------------------------------------------------------------------------------------------------------------- + protected boolean updateDependencies(WaitingProcess process) { + + boolean satisfied = true; + process = em.merge(process); + for (Dependency dependency : process.getDependencies()) { + if (dependency.getStatus() == DependencyStatus.UNSATISFIED) { + if (identityManager.getSystemIdById(process.getSystem(), dependency.getEntityId()) != null) { + /* Entity has a valid mapping => dependency satisfied */ + dependency.setStatus(DependencyStatus.SATISFIED); + } else { + satisfied = false; + } + } + } + return satisfied; } - public void persist(Object object) { - em.persist(object); + // ---------------------------------------------------------------------------------------------------------------- + protected void createDependency(WaitingProcess process, int entityId) { + + /* Check, if dependency does not already exist */ + for (Dependency dependency : process.getDependencies()) { + if (dependency.getEntityId() == entityId) { + return; + } + } + + /* Create new dependency */ + Dependency dependency = new Dependency(); + dependency.setProcess(process); + dependency.setEntityId(entityId); + dependency.setStatus(DependencyStatus.UNSATISFIED); + process.getDependencies().add(dependency); } - - + + // ---------------------------------------------------------------------------------------------------------------- + protected WaitingProcess getWaitingProcess(int entityId, String system) { + + WaitingProcess process = (WaitingProcess) em.createNamedQuery(WaitingProcess.QUERY_getByEntityIdAndSystem). setParameter("system", system). + setParameter("entityId", entityId). + getSingleResult(); + if (process == null) { + /* No existing process found => create a new one */ + process = new WaitingProcess(); + process.setEntityId(entityId); + process.setSystem(system); + em.persist(process); + } + + return process; + } + + // ---------------------------------------------------------------------------------------------------------------- + public void waitForDependencies(int cseId) { + + Entity entity = em.find(Entity.class, cseId); + + for (String system : systemManager.getOutboundSystems()) { + + /* Create entity type dependent dependencies */ + + WaitingProcess process = getWaitingProcess(cseId, system); + + if (entity.getType().equals(EntityType.ACCOUNT.toString())) { + /* No dependencies for account objects */ + } + + if (entity.getType().equals(EntityType.COURSE.toString())) { + /* Create dependencies based on category -> course relations (course is child) */ + List<Relation> relations = relationManager.getByChildIdAndType(cseId, RelationType.CATEGORY_TO_COURSE); + for (Relation relation : relations) { + createDependency(process, relation.getParentId()); + } + } + + if (entity.getType().equals(EntityType.CATEGORY.toString())) { + /* Create dependencies based von category -> course relations (category is parent) */ + List<Relation> relations = relationManager.getByParentIdAndType(cseId, RelationType.CATEGORY_TO_COURSE); + for (Relation relation : relations) { + WaitingProcess childProcess = getWaitingProcess(relation.getChildId(), system); + createDependency(childProcess, cseId); + } + + /* Create dependencies based von category -> catgeory relations (category is parent) */ + relations = relationManager.getByParentIdAndType(cseId, RelationType.CATEGORY_TO_COURSE); + for (Relation relation : relations) { + WaitingProcess childProcess = getWaitingProcess(relation.getChildId(), system); + createDependency(childProcess, cseId); + } + } + + /* At this point all dependencies for the current entity + system have been generated => so update them */ + if (updateDependencies(process)) { + wakeUpWaitingProcess(process); + } + } + } + + // ---------------------------------------------------------------------------------------------------------------- + protected List<Dependency> getByEntityIdAndSystem(int entityId, String system) { + + List<Dependency> dependencies = em.createNamedQuery(Dependency.QUERY_getByEntityIdAndSystem). setParameter("system", system). + setParameter("entityId", entityId). + getResultList(); + + return dependencies; + } + + // ---------------------------------------------------------------------------------------------------------------- + protected void wakeUpWaitingProcess(WaitingProcess process) { + + /* Call process */ + try { + org.netbeans.j2ee.wsdl.common.dependencymanagernotification.DependencyManagerNotificationPortType port = service.getDependencyManagerNotificationPort(); + + int entityId = process.getEntityId(); + String system = process.getSystem(); + + port.notify(entityId, system); + + } catch (Exception ex) { + logger.info("Exception while trying to notify process: " + ex.getMessage()); + } + + /* Remove dependencies */ + process = em.merge(process); + em.remove(process); + } + + // ---------------------------------------------------------------------------------------------------------------- + /** + * Satisfy all dependencies waiting for the given entity. + * + * @param entityId + */ + public void satisfyDependencies(int entityId, String system) { + + HashSet<WaitingProcess> processesToTest = new HashSet<WaitingProcess>(); + + /* Tag appropriate dependencies as satisfied */ + for (Dependency dependency : getByEntityIdAndSystem(entityId, system)) { + processesToTest.add(em.merge(dependency.getProcess())); + dependency.setStatus(DependencyStatus.SATISFIED); + } + + /* Wake-up waiting processes with all dependencies satisfied */ + for (WaitingProcess process : processesToTest) { + if (updateDependencies(process)) { + wakeUpWaitingProcess(process); + } + } + } } Deleted: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyStatus.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyStatus.java 2009-07-27 22:07:54 UTC (rev 379) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyStatus.java 2009-07-27 22:09:18 UTC (rev 380) @@ -1,9 +0,0 @@ -package de.campussource.cse.core; - -/** - * - * @author pete - */ -public enum DependencyStatus { - SATISFIED, UNSATISFIED -} Deleted: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyType.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyType.java 2009-07-27 22:07:54 UTC (rev 379) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/DependencyType.java 2009-07-27 22:09:18 UTC (rev 380) @@ -1,9 +0,0 @@ -package de.campussource.cse.core; - -/** - * - * @author pete - */ -public enum DependencyType { - NONE, COURSE, CATEGORY -} Added: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManager.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManager.java (rev 0) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManager.java 2009-07-27 22:09:18 UTC (rev 380) @@ -0,0 +1,19 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package de.campussource.cse.core; + +import java.util.List; +import javax.ejb.Local; + +/** + * + * @author pete + */ +@Local +public interface SystemManager { + + public List<String> getOutboundSystems(); +} Added: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManagerImpl.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManagerImpl.java (rev 0) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManagerImpl.java 2009-07-27 22:09:18 UTC (rev 380) @@ -0,0 +1,28 @@ +package de.campussource.cse.core; + +import java.util.LinkedList; +import java.util.List; +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +/** + * + * @author pete + */ + +@Stateless +public class SystemManagerImpl implements SystemManagerRemote, SystemManager { + + @PersistenceContext + private EntityManager em; + + public List<String> getOutboundSystems() { + + List<String> systems = new LinkedList<String>(); + systems.add("Ilias"); + + return systems; + } + +} Added: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManagerRemote.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManagerRemote.java (rev 0) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/SystemManagerRemote.java 2009-07-27 22:09:18 UTC (rev 380) @@ -0,0 +1,12 @@ +package de.campussource.cse.core; + +import javax.ejb.Remote; + +/** + * + * @author pete + */ +@Remote +public interface SystemManagerRemote extends SystemManager { + +} Added: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Dependency.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Dependency.java (rev 0) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Dependency.java 2009-07-27 22:09:18 UTC (rev 380) @@ -0,0 +1,103 @@ +package de.campussource.cse.core.pdm; + +import java.io.Serializable; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; + +/** + * + * @author pete + */ + +@NamedQueries({ + + @NamedQuery( name = "Dependency.getByEntityIdAndSystem", + query = "SELECT d FROM Dependency WHERE d.process.system = :system AND d.entityId = :entityId") +}) + +@Entity +public class Dependency implements Serializable { + + public static final String QUERY_getByEntityIdAndSystem = "Dependency.getByEntityIdAndSystem"; + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + /* Process associated with (= waiting on) this dependency */ + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "processId") + private WaitingProcess process; + + /* Entity this dependency refers to */ + private int entityId; + + /* Current status of this dependency */ + private DependencyStatus status; + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof Dependency)) { + return false; + } + Dependency other = (Dependency) object; + if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "de.campussource.cse.core.pdm.Dependency[id=" + id + "]"; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public WaitingProcess getProcess() { + return process; + } + + public void setProcess(WaitingProcess process) { + this.process = process; + } + + public DependencyStatus getStatus() { + return status; + } + + public void setStatus(DependencyStatus status) { + this.status = status; + } + + public int getEntityId() { + return entityId; + } + + public void setEntityId(int entityId) { + this.entityId = entityId; + } +} Added: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/DependencyStatus.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/DependencyStatus.java (rev 0) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/DependencyStatus.java 2009-07-27 22:09:18 UTC (rev 380) @@ -0,0 +1,9 @@ +package de.campussource.cse.core.pdm; + +/** + * + * @author pete + */ +public enum DependencyStatus { + SATISFIED, UNSATISFIED +} Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Entity.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Entity.java 2009-07-27 22:07:54 UTC (rev 379) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Entity.java 2009-07-27 22:09:18 UTC (rev 380) @@ -33,7 +33,7 @@ private boolean proxy; /* List of attributes of this object */ - @OneToMany(mappedBy="entity", cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @OneToMany(mappedBy = "entityId", cascade = CascadeType.ALL, fetch = FetchType.EAGER) private Collection<Attribute> attributes = new ArrayList<Attribute>(); @Override Added: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/WaitingProcess.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/WaitingProcess.java (rev 0) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/WaitingProcess.java 2009-07-27 22:09:18 UTC (rev 380) @@ -0,0 +1,107 @@ +package de.campussource.cse.core.pdm; + +import java.io.Serializable; +import java.util.Collection; +import java.util.LinkedList; +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; + +/** + * + * @author pete + */ + +@NamedQueries({ + + @NamedQuery( name = "WaitingProcess.getByEntityIdAndSystem", + query = "SELECT p FROM WaitingProcess p WHERE p.system = :system AND p.entityId = :entityId") +}) + +@Entity +public class WaitingProcess implements Serializable { + + public final static String QUERY_getByEntityIdAndSystem = "WaitingProcess.getByEntityIdAndSystem"; + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + /* Concrete dependencies associated with represented process instance */ + @OneToMany(mappedBy = "processId", cascade = CascadeType.ALL, fetch = FetchType.EAGER) + private Collection<Dependency> dependencies = new LinkedList<Dependency>(); + + /** + * Id of the associated process (will be used as correlation id for process-wakeup to identify + * the process instance) + */ + private int entityId; + + /* The system this process + associated dependencies relate to */ + private String system; + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof WaitingProcess)) { + return false; + } + WaitingProcess other = (WaitingProcess) object; + if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "de.campussource.cse.core.pdm.WaitingProcess[id=" + id + "]"; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Collection<Dependency> getDependencies() { + return dependencies; + } + + public void setDependencies(Collection<Dependency> dependencies) { + this.dependencies = dependencies; + } + + public int getEntityId() { + return entityId; + } + + public void setEntityId(int entityId) { + this.entityId = entityId; + } + + public String getSystem() { + return system; + } + + public void setSystem(String system) { + this.system = system; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |