*/
public List<Resource> get(ResourceType type) {
List<Resource> result = new ArrayList<Resource>();
EntityManager em = ResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator;
Query q;
switch (type) {
case PROJECT:
generator = new QueryGenerator(PROJECT);
Users users = em.find(Users.class, getUser());
Gateway gatewayModel = em.find(Gateway.class, gateway.getGatewayName());
generator.setParameter("users", users);
generator.setParameter("gateway", gatewayModel);
// generator.setParameter(ProjectConstants.USERNAME, getUser());
// generator.setParameter(ProjectConstants.GATEWAY_NAME, gateway.getGatewayName());
q = generator.selectQuery(em);
for (Object o : q.getResultList()) {
Project project = (Project) o;
ProjectResource projectResource = (ProjectResource)Utils.getResource(ResourceType.PROJECT, project);
result.add(projectResource);
}
break;
case USER_WORKFLOW:
generator = new QueryGenerator(USER_WORKFLOW);
generator.setParameter(UserWorkflowConstants.OWNER, getUser());
q = generator.selectQuery(em);
// q.setParameter("usr_name", getUser());
for (Object o : q.getResultList()) {
User_Workflow userWorkflow = (User_Workflow) o;
UserWorkflowResource userWorkflowResource = (UserWorkflowResource)Utils.getResource(ResourceType.USER_WORKFLOW, userWorkflow);
result.add(userWorkflowResource);
}
break;
case EXPERIMENT:
generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.USERNAME, getUser());
generator.setParameter(ExperimentConstants.GATEWAY_NAME, gateway.getGatewayName());
q = generator.selectQuery(em);
for (Object o : q.getResultList()) {
Experiment experiment = (Experiment) o;
ExperimentResource experimentResource = (ExperimentResource)Utils.getResource(ResourceType.EXPERIMENT, experiment);
result.add(experimentResource);
}