Exemplo n.º 1
0
 /**
  * Populate the response, given the object model object(DB Mapped object) This involves converting
  * the model object into the equivalent DTO for object and, then setting that DTO to the response.
  *
  * @param object The model object (Hibernate Mapped object)
  * @return The RestResponse containing the object details
  */
 public static RestResponse createResponse(BaseModel object, BaseDTO dtoObj) {
   RestResponse resp = new RestResponse();
   BaseDTO dto = dtoObj.getDTO((BaseModel) object);
   if (dto != null) {
     resp.setEntry(dto);
     resp.setTotalResults(1);
     resp.setItemsPerPage(1);
   }
   return resp;
 }
Exemplo n.º 2
0
 /**
  * Populate the response, given the list of objects of Model objects(Hibernate Mapped object) This
  * involves converting the model objects into the equivalent DTOs for object and, then setting
  * that DTOs to the response.
  *
  * @param objects The List of model objects (Hibernate Mapped objects)
  * @param totalCount The total count of objects in the object
  * @return The {@link RestResponse} containing the objects details
  */
 public static RestResponse createResponse(List objects, Integer totalCount, BaseDTO dtoObj) {
   RestResponse resp = new RestResponse();
   ArrayList<BaseDTO> list = null;
   /* populate only if the list is not empty */
   if (objects != null && objects.size() > 0) {
     list = new ArrayList<BaseDTO>(objects.size());
     for (Object object : objects) {
       BaseDTO dto = dtoObj.getDTO((BaseModel) object);
       if (dto != null) {
         list.add(dto);
       }
     }
   }
   /* if the list contains some elements, then set the response */
   if (list != null && list.size() > 0) {
     resp.setEntries(list);
     resp.setItemsPerPage(list.size());
     resp.setTotalResults(totalCount);
   }
   return resp;
 }