/**
  * Executes request to server.
  *
  * @param request <code>DSRequest</code> being processed.
  * @return <code>Object</code> data from original request.
  */
 protected Object transformRequest(DSRequest request) {
   String requestId = request.getRequestId();
   DSResponse response = new DSResponse();
   response.setAttribute("clientContext", request.getAttributeAsObject("clientContext"));
   // Asume success
   response.setStatus(0);
   switch (request.getOperationType()) {
     case FETCH:
       executeFetch(requestId, request, response);
       break;
     case ADD:
       executeAdd(requestId, request, response);
       break;
     case UPDATE:
       executeUpdate(requestId, request, response);
       break;
     case REMOVE:
       executeRemove(requestId, request, response);
       break;
     default:
       // Operation not implemented.
       break;
   }
   return request.getData();
 }
  @Override
  protected Object transformRequest(DSRequest request) {
    DSResponse response = new DSResponse();
    response.setAttribute("clientContext", request.getAttributeAsObject("clientContext"));
    // Asume success
    response.setStatus(0);
    switch (request.getOperationType()) {
      case FETCH:
        executeFetch(request, response);
        break;
      default:
        break;
    }

    return request.getData();
  }
Ejemplo n.º 3
0
 @Override
 protected void transformResponse(DSResponse dsResponse, DSRequest dsRequest, Object data) {
   if (RestConfig.isStatusOk(dsResponse)) {
     Record[] records = dsResponse.getData();
     for (Record record : records) {
       String mid = record.getAttribute(FIELD_ID);
       String way = record.getAttribute(FIELD_WAY);
       String pk = mid;
       if (way != null) {
         pk = mid + way;
       }
       record.setAttribute(PRIMARY_KEY, pk);
     }
   }
   super.transformResponse(dsResponse, dsRequest, data);
 }
  public void executeFetch(final DSRequest request, final DSResponse response) {

    long ctime = -1;
    int maxItems = -1;
    // retrieve current portlet display settings
    if ((this.portlet != null) && (this.portlet instanceof RecentlyAddedResourcesPortlet)) {
      RecentlyAddedResourcesPortlet recentAdditionsPortlet =
          (RecentlyAddedResourcesPortlet) this.portlet;
      if (recentAdditionsPortlet != null) {
        if (getMaximumRecentlyAddedToDisplay() > 0) {
          maxItems = getMaximumRecentlyAddedToDisplay();
        }

        // define the time window
        if (getMaximumRecentlyAddedWithinHours() > 0) {
          ctime =
              System.currentTimeMillis()
                  - (getMaximumRecentlyAddedWithinHours() * MeasurementUtility.HOURS);
          setOldestDate(ctime);
        }
      }
    }

    // TODO: spinder: revisit this later. ResourceCriteria mechanism does not work. Not sure if it's
    // better?
    //        ResourceCriteria c = new ResourceCriteria();
    //
    //        String p = request.getCriteria().getAttribute("parentId");
    //
    //        if (p == null) {
    //            c.addFilterResourceCategory(ResourceCategory.PLATFORM);
    //            c.fetchChildResources(true);
    //        } else {
    //            c.addFilterParentResourceId(Integer.parseInt(p));
    //        }

    // TODO GH: Enhance resourceCriteria query to support itime based filtering for
    // "Recently imported" resources

    // if logged in then proceed making server side calls
    if (UserSessionManager.isLoggedIn()) {
      GWTServiceLookup.getResourceService()
          .findRecentlyAddedResources(
              ctime,
              maxItems,
              new AsyncCallback<List<RecentlyAddedResourceComposite>>() {
                public void onFailure(Throwable throwable) {
                  CoreGUI.getErrorHandler()
                      .handleError(MSG.view_portlet_recentlyAdded_error1(), throwable);
                }

                public void onSuccess(List<RecentlyAddedResourceComposite> recentlyAddedList) {
                  List<RecentlyAddedResourceComposite> list =
                      new ArrayList<RecentlyAddedResourceComposite>();

                  for (RecentlyAddedResourceComposite recentlyAdded : recentlyAddedList) {
                    list.add(recentlyAdded);
                    list.addAll(recentlyAdded.getChildren());
                  }

                  response.setData(buildNodes(list));
                  response.setTotalRows(list.size());
                  processResponse(request.getRequestId(), response);
                }
              });
    } else { //
      Log.debug("user is not logged in. Not fetching recently added resource now.");
      // answer the datasource
      response.setTotalRows(0);
      processResponse(request.getRequestId(), response);
    }
  }