Show TOC Start of Content Area

Syntax documentation ProjectManagementService Source Code  Locate the document in its SAP Library structure

package com.sap.nwce.ra.edm.ejb.services;

 

import java.util.List;

 

import javax.annotation.Resource;

import javax.annotation.Resource.AuthenticationType;

import javax.ejb.EJB;

import javax.ejb.SessionContext;

import javax.ejb.Stateless;

import javax.ejb.TransactionAttribute;

import javax.ejb.TransactionAttributeType;

import javax.persistence.EntityManager;

import javax.persistence.PersistenceContext;

import javax.persistence.PersistenceContextType;

import javax.persistence.Query;

 

import com.sap.nwce.ra.edm.ejb.entity.CeraProject;

 

@Stateless

public class ProjectManagementServiceBean implements

      ProjectManagementServiceLocal {

  

   @PersistenceContext(unitName="ems/EJB3_EDM_DEMO_PU", type=PersistenceContextType.TRANSACTION)

   private EntityManager em;

 

   @Resource(name="resource1", authenticationType=AuthenticationType.CONTAINER, type=Object.class)

   private SessionContext sessionCtx;

 

   @EJB(name="JMSSenderSessionLocal", beanName="DefaultBeanName", beanInterface=Object.class)

   private ProjectChangeSenderLocal jmsSender;

   /**

 

       * Get a project by its id.

 

       * @return project entity

 

       */

 

    

 

      public CeraProject getProjectById(String pId){

 

         return em.find(CeraProject.class, Integer.valueOf(pId));

 

      }

 

     

 

      /**

 

       * Get all projects in a single list.

 

       * @return list of all projects

 

       */

 

      @SuppressWarnings("unchecked")

 

      public List<CeraProject> getAllProjects(){

 

         Query query = em.createNamedQuery("Project.getAll");

 

         List<CeraProject> result = query.getResultList();

 

         return result;

 

      }

 

    

 

      /**

 

       * Get all assigned projects.

 

       * @return list of all assigned projects

 

       */

 

      @SuppressWarnings("unchecked")

 

      public List<CeraProject> getAssignedProjects(int pEmployeeId){ 

 

         Query query = em.createNamedQuery("Project.getAllForEmployee");

 

         query.setParameter("employeeId", pEmployeeId);

 

         List<CeraProject> result = query.getResultList();

 

         return result;

 

      }

 

    

 

      /**

 

       * Removes a project.

 

       * @param pProject

 

       */

 

      public void removeProject(CeraProject pProject){

 

         em.remove(pProject);

 

      }

 

     

 

      /**

 

       * Persists a project (create or update) and sends a message to

 

       * the projectchangequeue to notify the system that the project

 

       * was changed

 

       */

 

      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

 

      public CeraProject createProject(CeraProject pProject){

 

         CeraProject result = em.merge(pProject);

 

         String caller = sessionCtx.getCallerPrincipal().getName();

 

         jmsSender.sendMessage(result, caller);

 

         return result;

 

      }

 

    

 

      /**

 

       * Get a list of projects by its name or description.

 

       * @param Name or description fragment

 

       * @return List of projects

 

       */

 

      @SuppressWarnings("unchecked")

 

      public List<CeraProject> findProjectByNameOrDescription(String pNameFragment){

 

         Query query = em.createNamedQuery("Project.findByNameOrDescPart");

 

         String parameter = pNameFragment.toLowerCase();

 

         query.setParameter("namepart", "%"+parameter+"%");

 

         query.setParameter("namepart1", "%"+parameter+"%");

 

         List<CeraProject> result = query.getResultList();

 

         return result;

 

      }

 

}

 

 

End of Content Area