|
From: <pka...@us...> - 2009-07-31 21:40:49
|
Revision: 412
http://cse-ip.svn.sourceforge.net/cse-ip/?rev=412&view=rev
Author: pkasprzak
Date: 2009-07-31 21:40:29 +0000 (Fri, 31 Jul 2009)
Log Message:
-----------
* Added get*Context() + WS-Interface
Modified Paths:
--------------
trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManager.java
trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerImpl.java
trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerWS.java
Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManager.java
===================================================================
--- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManager.java 2009-07-31 21:40:08 UTC (rev 411)
+++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManager.java 2009-07-31 21:40:29 UTC (rev 412)
@@ -15,19 +15,25 @@
@Local
public interface EntityManager {
- public int exists(String system, String systemId);
+ public int exists(String system, String systemId);
- public int createAccount(de.campussource.cse.core.cdm.AccountType account);
+ public int createAccount(de.campussource.cse.core.cdm.AccountType account);
- public int createCourse(de.campussource.cse.core.cdm.CourseType course);
+ public int createCourse(de.campussource.cse.core.cdm.CourseType course);
- public int createCategory(de.campussource.cse.core.cdm.CategoryType category);
+ public int createCategory(de.campussource.cse.core.cdm.CategoryType category);
- public int createProxy(String type);
+ public de.campussource.cse.core.cdm.AccountType getAccountContext(int entityId, String system);
- public boolean updateAttributes(de.campussource.cse.core.cdm.EntityType entity);
+ public de.campussource.cse.core.cdm.CourseType getCourseContext(int entityId, String system);
- public void deleteEntity(int cseId);
+ public de.campussource.cse.core.cdm.CategoryType getCategoryContext(int entityId, String system);
- public Entity getEntity(int cseId);
+ public int createProxy(String type);
+
+ public boolean updateAttributes(de.campussource.cse.core.cdm.EntityType entity);
+
+ public void deleteEntity(int entityId);
+
+ public Entity getEntity(int entityId);
}
Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerImpl.java
===================================================================
--- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerImpl.java 2009-07-31 21:40:08 UTC (rev 411)
+++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerImpl.java 2009-07-31 21:40:29 UTC (rev 412)
@@ -8,6 +8,8 @@
import de.campussource.cse.core.pdm.Attribute;
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 java.util.HashMap;
import java.util.LinkedList;
import java.util.logging.Logger;
@@ -28,6 +30,9 @@
@EJB
private IdentityManager identityManager;
+ @EJB
+ private RelationManager relationManager;
+
private final static Logger logger = Logger.getLogger("de.campussource.cse.core.EntityManager");
// ----------------------------------------------------------------------------------------------------------------
@@ -50,15 +55,33 @@
protected void convertAttributes(de.campussource.cse.core.cdm.EntityType xmlEntity, Entity entity) {
for (AttributeType xmlAttribute : xmlEntity.getAttribute()) {
+
Attribute attribute = new Attribute();
+
attribute.setEntity(entity);
attribute.setName(xmlAttribute.getName());
attribute.setValue(xmlAttribute.getValue());
+
entity.getAttributes().add(attribute);
}
}
// ----------------------------------------------------------------------------------------------------------------
+ protected void convertAttributes(Entity entity, de.campussource.cse.core.cdm.EntityType xmlEntity) {
+
+ for (Attribute attribute : entity.getAttributes()) {
+
+ AttributeType xmlAttribute = new AttributeType();
+
+ xmlAttribute.setName(attribute.getName());
+ xmlAttribute.setValue(attribute.getValue());
+ xmlAttribute.setTransient(false);
+
+ xmlEntity.getAttribute().add(xmlAttribute);
+ }
+ }
+
+ // ----------------------------------------------------------------------------------------------------------------
protected int persistEntity(Entity entity) {
em.persist(entity);
@@ -197,4 +220,91 @@
Entity entity = em.find(Entity.class, cseId);
return entity;
}
+
+ // ----------------------------------------------------------------------------------------------------------------
+ public AccountType getAccountContext(int entityId, String system) {
+
+ Entity entity = em.find(Entity.class, entityId);
+
+ if (entity == null) {
+ logger.severe("No entity with id [" + entityId + "] found!");
+ return null;
+ }
+
+ if (!entity.getType().equals(EntityType.ACCOUNT.toString())) {
+ logger.severe("Entity [" + entityId + "] has wrong type: [" + EntityType.ACCOUNT + "] expected vs. [" + entity.getType() + "] obtained!");
+ return null;
+ }
+
+ AccountType xmlAccount = new AccountType();
+
+ convertAttributes(entity, xmlAccount);
+ xmlAccount.setBusId(entityId);
+
+ return xmlAccount;
+ }
+
+ // ----------------------------------------------------------------------------------------------------------------
+ public CourseType getCourseContext(int entityId, String system) {
+
+ Entity entity = em.find(Entity.class, entityId);
+
+ if (entity == null) {
+ logger.severe("No entity with id [" + entityId + "] found!");
+ return null;
+ }
+
+ if (!entity.getType().equals(EntityType.COURSE.toString())) {
+ logger.severe("Entity [" + entityId + "] has wrong type: [" + EntityType.COURSE + "] expected vs. [" + entity.getType() + "] obtained!");
+ return null;
+ }
+
+ CourseType xmlCourse = new CourseType();
+
+ convertAttributes(entity, xmlCourse);
+ xmlCourse.setBusId(entityId);
+
+ /* Set category -> course (course is child) relations */
+ for (Relation relation : relationManager.getByChildIdAndType(entityId, RelationType.CATEGORY_TO_COURSE)) {
+ String systemId = identityManager.getSystemIdById(system, relation.getParentId());
+ xmlCourse.getCategories().getCategory().add(systemId);
+ }
+
+ return xmlCourse;
+ }
+
+ // ----------------------------------------------------------------------------------------------------------------
+ public CategoryType getCategoryContext(int entityId, String system) {
+
+ Entity entity = em.find(Entity.class, entityId);
+
+ if (entity == null) {
+ logger.severe("No entity with id [" + entityId + "] found!");
+ return null;
+ }
+
+ if (!entity.getType().equals(EntityType.CATEGORY.toString())) {
+ logger.severe("Entity [" + entityId + "] has wrong type: [" + EntityType.CATEGORY + "] expected vs. [" + entity.getType() + "] obtained!");
+ return null;
+ }
+
+ CategoryType xmlCategory = new CategoryType();
+
+ convertAttributes(entity, xmlCategory);
+ xmlCategory.setBusId(entityId);
+
+ /* Set category -> course (category is parent) relations */
+ for (Relation relation : relationManager.getByParentIdAndType(entityId, RelationType.CATEGORY_TO_COURSE)) {
+ String systemId = identityManager.getSystemIdById(system, relation.getChildId());
+ xmlCategory.getCourses().getCourse().add(systemId);
+ }
+
+ /* Set category -> category (category is parent) relations */
+ for (Relation relation : relationManager.getByParentIdAndType(entityId, RelationType.CATEGORY_TO_CATEGORY)) {
+ String systemId = identityManager.getSystemIdById(system, relation.getChildId());
+ xmlCategory.getCategories().getCategory().add(systemId);
+ }
+
+ return xmlCategory;
+ }
}
Modified: trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerWS.java
===================================================================
--- trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerWS.java 2009-07-31 21:40:08 UTC (rev 411)
+++ trunk/sandbox/lsf-adapter-demo/CSECore-ejb/src/java/de/campussource/cse/core/EntityManagerWS.java 2009-07-31 21:40:29 UTC (rev 412)
@@ -22,33 +22,51 @@
private EntityManager ejbRef;
@WebMethod(operationName = "exists")
- public int exists( @WebParam(name = "system") String system,
- @WebParam(name = "systemId") String systemId) {
+ public int exists( @WebParam(name = "system") String system,
+ @WebParam(name = "systemId") String systemId) {
return ejbRef.exists(system, systemId);
}
@WebMethod(operationName = "persistAccount")
- public int persistAccount( @WebParam(name = "account") AccountType account) {
+ public int persistAccount( @WebParam(name = "account") AccountType account) {
return ejbRef.createAccount(account);
}
@WebMethod(operationName = "persistCourse")
- public int persistCourse( @WebParam(name = "course") CourseType course) {
+ public int persistCourse( @WebParam(name = "course") CourseType course) {
return ejbRef.createCourse(course);
}
@WebMethod(operationName = "persistCategory")
- public int persistCategory( @WebParam(name = "category") CategoryType category) {
+ public int persistCategory( @WebParam(name = "category") CategoryType category) {
return ejbRef.createCategory(category);
}
@WebMethod(operationName = "persistProxy")
- public int persistProxy( @WebParam(name = "type") String type) {
+ public int persistProxy( @WebParam(name = "type") String type) {
return ejbRef.createProxy(type);
}
@WebMethod(operationName = "updateAttributes")
- public boolean updateAttributes(@WebParam(name = "entity") EntityType entity) {
+ public boolean updateAttributes( @WebParam(name = "entity") EntityType entity) {
return ejbRef.updateAttributes(entity);
}
+
+ @WebMethod(operationName = "getAccountContext")
+ public AccountType getAccountContext( @WebParam(name = "entityId") int entityId,
+ @WebParam(name = "system") String system) {
+ return ejbRef.getAccountContext(entityId, system);
+ }
+
+ @WebMethod(operationName = "getCourseContext")
+ public CourseType getCourseContext( @WebParam(name = "entityId") int entityId,
+ @WebParam(name = "system") String system) {
+ return ejbRef.getCourseContext(entityId, system);
+ }
+
+ @WebMethod(operationName = "getCategoryContext")
+ public CategoryType getCategoryContext( @WebParam(name = "entityId") int entityId,
+ @WebParam(name = "system") String system) {
+ return ejbRef.getCategoryContext(entityId, system);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|