From: <pka...@us...> - 2009-07-25 09:17:39
|
Revision: 377 http://cse-ip.svn.sourceforge.net/cse-ip/?rev=377&view=rev Author: pkasprzak Date: 2009-07-25 09:17:32 +0000 (Sat, 25 Jul 2009) Log Message: ----------- * Make relation management logic available to bpel processes Modified Paths: -------------- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/nbproject/build-impl.xml trunk/sandbox/lsf-adapter-demo/CSECore-ejb/nbproject/genfiles.properties trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManager.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManagerImpl.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManagerWS.java trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Relation.java Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/nbproject/build-impl.xml =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/nbproject/build-impl.xml 2009-07-25 09:17:13 UTC (rev 376) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/nbproject/build-impl.xml 2009-07-25 09:17:32 UTC (rev 377) @@ -16,8 +16,8 @@ --> <project xmlns:ejbjarproject1="http://www.netbeans.org/ns/j2ee-ejbjarproject/1" xmlns:ejbjarproject2="http://www.netbeans.org/ns/j2ee-ejbjarproject/2" xmlns:ejbjarproject3="http://www.netbeans.org/ns/j2ee-ejbjarproject/3" basedir=".." default="default" name="CSECore-ejb-impl"> + <import file="xml_binding_build.xml"/> <import file="jaxws-build.xml"/> - <import file="xml_binding_build.xml"/> <import file="ant-deploy.xml"/> <target depends="dist,javadoc" description="Build whole project." name="default"/> <!-- Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/nbproject/genfiles.properties =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/nbproject/genfiles.properties 2009-07-25 09:17:13 UTC (rev 376) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/nbproject/genfiles.properties 2009-07-25 09:17:32 UTC (rev 377) @@ -4,6 +4,6 @@ # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=8344d0cf -nbproject/build-impl.xml.script.CRC32=7e7d23ca +nbproject/build-impl.xml.script.CRC32=91803eb0 nbproject/build-impl.xml.stylesheet.CRC32=36c39d59 nbproject/jaxws-build.xml.stylesheet.CRC32=f49c6152 Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManager.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManager.java 2009-07-25 09:17:13 UTC (rev 376) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManager.java 2009-07-25 09:17:32 UTC (rev 377) @@ -29,9 +29,11 @@ public void deleteByParentId(int parentId); - public void createRelationsFromAccount(int cseId, de.campussource.cse.core.cdm.AccountType account, String system); + public void delete(int childId, int parentId, RelationType type); - public void createRelationsFromCourse(int cseId, de.campussource.cse.core.cdm.CourseType course, String system); + public boolean processAccountRelations(int cseId, de.campussource.cse.core.cdm.AccountType account, java.lang.String system); - public void createRelationsFromCategory(int cseId, de.campussource.cse.core.cdm.CategoryType category, String system); + public boolean processCourseRelations(int cseId, de.campussource.cse.core.cdm.CourseType course, java.lang.String system); + + public boolean processCategoryRelations(int cseId, de.campussource.cse.core.cdm.CategoryType category, java.lang.String system); } Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManagerImpl.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManagerImpl.java 2009-07-25 09:17:13 UTC (rev 376) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManagerImpl.java 2009-07-25 09:17:32 UTC (rev 377) @@ -7,6 +7,7 @@ import de.campussource.cse.core.pdm.EntityType; import de.campussource.cse.core.pdm.Relation; import de.campussource.cse.core.pdm.RelationType; +import java.util.HashSet; import java.util.List; import java.util.logging.Logger; import javax.ejb.EJB; @@ -43,59 +44,140 @@ } // ---------------------------------------------------------------------------------------------------------------- - public void createRelationsFromAccount(int cseId, AccountType account, String system) { + public boolean processAccountRelations(int cseId, AccountType account, String system) { + logger.info("Creating relations from account for account:" + Utils.dumpEntity(account, true)); + return false; } // ---------------------------------------------------------------------------------------------------------------- - public void createRelationsFromCourse(int cseId, CourseType course, String system) { + public boolean processCourseRelations(int cseId, CourseType course, String system) { - /* Handle category -> course relations */ - for (String relationId : course.getCategories().getCategory()) { + boolean relationsUpdated = false; + /* Handle category -> course relations (this course is child) */ + + HashSet<Integer> persistedRelationSet = new HashSet<Integer>(); + HashSet<Integer> xmlRelationsSet = new HashSet<Integer>(); + + for (Relation relation : getByChildIdAndType(cseId, RelationType.CATEGORY_TO_COURSE)) { + persistedRelationSet.add(relation.getParentId()); + } + + for (String categoryId : course.getCategories().getCategory()) { + /* Try to resolve partner entity id */ - Integer partnerId = identityManager.getIdBySystemId(system, relationId); + Integer partnerId = identityManager.getIdBySystemId(system, categoryId); if (partnerId == null) { /* Object does not exist => create proxy */ partnerId = entityManager.createProxy(EntityType.CATEGORY.toString()); } - /* Create relation */ - createRelation(cseId, partnerId, RelationType.CATEGORY_TO_COURSE); + /* Keep track of xml relations for later */ + xmlRelationsSet.add(partnerId); + + /* Create relation if new */ + if (!persistedRelationSet.contains(partnerId)) { + /* Relation new => create */ + createRelation(cseId, partnerId, RelationType.CATEGORY_TO_COURSE); + relationsUpdated = true; + } } + + /* Check for relations to be deleted */ + persistedRelationSet.removeAll(xmlRelationsSet); + if (!persistedRelationSet.isEmpty()) { + relationsUpdated = true; + for (Integer parentId : persistedRelationSet) { + delete(cseId, parentId, RelationType.CATEGORY_TO_COURSE); + } + } + + return relationsUpdated; } // ---------------------------------------------------------------------------------------------------------------- - public void createRelationsFromCategory(int cseId, CategoryType category, String system) { + public boolean processCategoryRelations(int cseId, CategoryType category, String system) { - /* Handle category -> course relations */ - for (String relationId : category.getCourses().getCourse()) { + boolean relationsUpdated = false; + /* Handle category -> course relations (this category is parent) */ + + HashSet<Integer> persistedRelationSet = new HashSet<Integer>(); + HashSet<Integer> xmlRelationsSet = new HashSet<Integer>(); + + for (Relation relation : getByParentIdAndType(cseId, RelationType.CATEGORY_TO_COURSE)) { + persistedRelationSet.add(relation.getChildId()); + } + + for (String courseId : category.getCourses().getCourse()) { + /* Try to resolve partner entity id */ - Integer partnerId = identityManager.getIdBySystemId(system, relationId); + Integer partnerId = identityManager.getIdBySystemId(system, courseId); if (partnerId == null) { /* Object does not exist => create proxy */ partnerId = entityManager.createProxy(EntityType.COURSE.toString()); } - /* Create relation */ - createRelation(partnerId, cseId, RelationType.CATEGORY_TO_COURSE); + /* Keep track of xml relations for later */ + xmlRelationsSet.add(partnerId); + + /* Create relation if new */ + if (!persistedRelationSet.contains(partnerId)) { + /* Relation new => create */ + createRelation(partnerId, cseId, RelationType.CATEGORY_TO_COURSE); + relationsUpdated = true; + } } - /* Handle category -> category relations */ - for (String relationId : category.getCategories().getCategory()) { + /* Check for relations to be deleted */ + persistedRelationSet.removeAll(xmlRelationsSet); + if (!persistedRelationSet.isEmpty()) { + relationsUpdated = true; + for (Integer childId : persistedRelationSet) { + delete(childId, cseId, RelationType.CATEGORY_TO_COURSE); + } + } + /* Handle category -> category relations (this category is parent) */ + + xmlRelationsSet.clear(); + persistedRelationSet.clear(); + + for (Relation relation : getByParentIdAndType(cseId, RelationType.CATEGORY_TO_CATEGORY)) { + persistedRelationSet.add(relation.getChildId()); + } + + for (String categoryId : category.getCategories().getCategory()) { + /* Try to resolve partner entity id */ - Integer partnerId = identityManager.getIdBySystemId(system, relationId); + Integer partnerId = identityManager.getIdBySystemId(system, categoryId); if (partnerId == null) { /* Object does not exist => create proxy */ partnerId = entityManager.createProxy(EntityType.CATEGORY.toString()); } - /* Create relation */ - createRelation(partnerId, cseId, RelationType.CATEGORY_TO_CATEGORY); + /* Keep track of xml relations for later */ + xmlRelationsSet.add(partnerId); + + /* Create relation if new */ + if (!persistedRelationSet.contains(partnerId)) { + /* Relation new => create */ + createRelation(partnerId, cseId, RelationType.CATEGORY_TO_CATEGORY); + relationsUpdated = true; + } } + /* Check for relations to be deleted */ + persistedRelationSet.removeAll(xmlRelationsSet); + if (!persistedRelationSet.isEmpty()) { + relationsUpdated = true; + for (Integer childId : persistedRelationSet) { + delete(childId, cseId, RelationType.CATEGORY_TO_CATEGORY); + } + } + + return relationsUpdated; } // ---------------------------------------------------------------------------------------------------------------- @@ -120,7 +202,6 @@ List<Relation> relations = em.createNamedQuery(Relation.QUERY_getByChildId). setParameter("childId", childId). getResultList(); return relations; - } // ---------------------------------------------------------------------------------------------------------------- @@ -129,7 +210,6 @@ List<Relation> relations = em.createNamedQuery(Relation.QUERY_getByChildIdAndType). setParameter("childId", childId). getResultList(); return relations; - } // ---------------------------------------------------------------------------------------------------------------- @@ -144,6 +224,14 @@ em.createNamedQuery(Relation.QUERY_deleteByParentId). setParameter("parentId", parentId). executeUpdate(); + } + // ---------------------------------------------------------------------------------------------------------------- + public void delete(int childId, int parentId, RelationType type) { + + em.createNamedQuery(Relation.QUERY_delete). setParameter("childId", childId). + setParameter("parentId", parentId). + setParameter("type", type). + executeUpdate(); } } Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManagerWS.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManagerWS.java 2009-07-25 09:17:13 UTC (rev 376) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/RelationManagerWS.java 2009-07-25 09:17:32 UTC (rev 377) @@ -3,6 +3,9 @@ import de.campussource.cse.core.cdm.AccountType; import de.campussource.cse.core.cdm.CategoryType; import de.campussource.cse.core.cdm.CourseType; +import de.campussource.cse.core.pdm.Relation; +import de.campussource.cse.core.pdm.RelationType; +import java.util.List; import javax.ejb.EJB; import javax.jws.Oneway; import javax.jws.WebMethod; @@ -21,27 +24,77 @@ @EJB private RelationManager ejbRef; - @WebMethod(operationName = "createRelationsFromAccount") +/* + @WebMethod(operationName = "getByParentId") + public List<Relation> getByParentId( @WebParam(name = "parentId") int parentId) { + + return ejbRef.getByParentId(parentId); + } + + @WebMethod(operationName = "getByParentIdAndType") + public List<Relation> getByParentIdAndType( @WebParam(name = "parentId") int parentId, + @WebParam(name = "type") RelationType type) { + + return ejbRef.getByParentIdAndType(parentId, type); + } + + @WebMethod(operationName = "getByChildId") + public List<Relation> getByChildId( @WebParam(name = "childId") int childId) { + + return ejbRef.getByChildId(childId); + } + + @WebMethod(operationName = "getByChildIdAndType") + public List<Relation> getByChildIdAndType( @WebParam(name = "childId") int childId, + @WebParam(name = "type") RelationType type) { + + return ejbRef.getByChildIdAndType(childId, type); + } + + @WebMethod(operationName = "deleteByChildId") @Oneway - public void createRelationsFromAccount( @WebParam(name = "cseId") int cseId, - @WebParam(name = "account") AccountType account, - @WebParam(name = "system") String system) { - ejbRef.createRelationsFromAccount(cseId, account, system); + public void deleteByChildId( @WebParam(name = "childId") int childId) { + + ejbRef.deleteByChildId(childId); } - @WebMethod(operationName = "createRelationsFromCourse") + @WebMethod(operationName = "deleteByParentId") @Oneway - public void createRelationsFromCourse( @WebParam(name = "cseId") int cseId, - @WebParam(name = "course") CourseType course, - @WebParam(name = "system") String system) { - ejbRef.createRelationsFromCourse(cseId, course, system); + public void deleteByParentId( @WebParam(name = "parentId") int parentId) { + + ejbRef.deleteByParentId(parentId); } - @WebMethod(operationName = "createRelationsFromCategory") + @WebMethod(operationName = "delete") @Oneway - public void createRelationsFromCategory( @WebParam(name = "cseId") int cseId, - @WebParam(name = "category") CategoryType category, - @WebParam(name = "system") String system) { - ejbRef.createRelationsFromCategory(cseId, category, system); + public void delete( @WebParam(name = "childId") int childId, + @WebParam(name = "parentId") int parentId, + @WebParam(name = "type") RelationType type) { + + ejbRef.delete(childId, parentId, type); } +*/ + @WebMethod(operationName = "processAccountRelations") + public boolean processAccountRelations( @WebParam(name = "cseId") int cseId, + @WebParam(name = "account") AccountType account, + @WebParam(name = "system") String system) { + + return ejbRef.processAccountRelations(cseId, account, system); + } + + @WebMethod(operationName = "processCourseRelations") + public boolean processCourseRelations( @WebParam(name = "cseId") int cseId, + @WebParam(name = "course") CourseType course, + @WebParam(name = "system") String system) { + + return ejbRef.processCourseRelations(cseId, course, system); + } + + @WebMethod(operationName = "processCategoryRelations") + public boolean processCategoryRelations( @WebParam(name = "cseId") int cseId, + @WebParam(name = "category") CategoryType category, + @WebParam(name = "system") String system) { + + return ejbRef.processCategoryRelations(cseId, category, system); + } } Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Relation.java =================================================================== --- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Relation.java 2009-07-25 09:17:13 UTC (rev 376) +++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/pdm/Relation.java 2009-07-25 09:17:32 UTC (rev 377) @@ -32,8 +32,10 @@ query = "DELETE FROM Relation r WHERE r.childId = :childId"), @NamedQuery( name = "Relation.deleteByParentId", - query = "DELETE FROM Relation r WHERE r.parentId = :parentId") + query = "DELETE FROM Relation r WHERE r.parentId = :parentId"), + @NamedQuery( name = "Relation.delete", + query = "DELETE FROM Relation r WHERE r.parentId = :parentId AND r.childId = :childId AND r.type = :type") }) @Entity @@ -45,6 +47,7 @@ public final static String QUERY_getByChildIdAndType = "Relation.getByChildIdAndType"; public final static String QUERY_deleteByChildId = "Relation.deleteByChildId"; public final static String QUERY_deleteByParentId = "Relation.deleteByParentId"; + public final static String QUERY_delete = "Relation.delete"; private static final long serialVersionUID = 1L; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |