コード例 #1
0
 /**
  * get all projectModules
  *
  * @param variant client preferred media type
  * @return Representation
  */
 @Get
 public Representation retrieveProjectModule(Variant variant) {
   try {
     if (getProjectModuleId() != null) {
       ProjectModuleModel projectModule = getStore().retrieve(getProjectModuleId());
       Response response;
       if (projectModule != null) {
         trace(Level.FINE, "Edit information for the module " + projectModule.getName());
         response = new Response(true, projectModule, ProjectModuleModel.class, "projectModule");
       } else {
         trace(Level.INFO, "Cannot edit information for the module - id: " + getProjectModuleId());
         response = new Response(false, "NO_MODULE_FOUND");
       }
       return getRepresentation(response, variant);
     } else {
       ResourceCollectionFilter filter = new ResourceCollectionFilter(this.getRequest());
       List<ProjectModuleModel> projectModules = getStore().getList(filter);
       int total = projectModules.size();
       projectModules = getStore().getPage(filter, projectModules);
       trace(Level.INFO, "View available modules");
       Response response =
           new Response(true, projectModules, ProjectModuleModel.class, "projectModules");
       response.setTotal(total);
       return getRepresentation(response, variant);
     }
   } catch (ResourceException e) {
     trace(Level.INFO, "Cannot view available modules");
     getLogger().log(Level.INFO, null, e);
     throw e;
   } catch (Exception e) {
     trace(Level.INFO, "Cannot view available modules");
     getLogger().log(Level.WARNING, null, e);
     throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e);
   }
 }
  /**
   * Delete the given Order
   *
   * @param order the order to delete
   */
  protected void deleteOrder(Order order) {
    // TODO Auto-generated method stub
    String url = getOrderUrl() + "/" + order.getId();

    ClientResource cr = new ClientResource(url);
    ChallengeResponse chal = new ChallengeResponse(ChallengeScheme.HTTP_BASIC, userLogin, password);

    cr.setChallengeResponse(chal);

    Representation result = cr.delete(getMediaTest());
    assertNotNull(result);
    assertTrue(cr.getStatus().isSuccess());
    Response response = getResponseOrderandUserstorage(getMediaTest(), result, Order.class);
    assertTrue(response.getSuccess());
    result.release();
  }
  /**
   * Get the Order at the given url
   *
   * @param url the url where to find the Order
   * @return the Order found
   */
  protected Order getOrder(String url) {

    ClientResource cr = new ClientResource(url);

    ChallengeResponse chal = new ChallengeResponse(ChallengeScheme.HTTP_BASIC, userLogin, password);

    cr.setChallengeResponse(chal);

    Representation result = cr.get(getMediaTest());
    assertNotNull(result);
    assertTrue(cr.getStatus().isSuccess());
    Response response = getResponseOrderandUserstorage(getMediaTest(), result, Order.class);
    assertTrue(response.getSuccess());
    result.release();
    return (Order) response.getItem();
  }
  /** Assert if there are no Orders */
  protected void assertNoneOrder() {

    ClientResource cr = new ClientResource(getOrderUrl());
    ChallengeResponse chal = new ChallengeResponse(ChallengeScheme.HTTP_BASIC, userLogin, password);

    cr.setChallengeResponse(chal);

    Representation result = cr.get(getMediaTest());

    assertNotNull(result);
    assertTrue(cr.getStatus().isSuccess());

    Response response = getResponseOrderandUserstorage(getMediaTest(), result, Order.class, true);
    assertTrue(response.getSuccess());
    assertEquals(0, response.getTotal().intValue());
  }
コード例 #5
0
  /**
   * Invoke POST
   *
   * @param item DataSet
   */
  public void create(DataSet item) {
    Representation rep =
        GetRepresentationUtils.getRepresentationDataset(item, MediaType.APPLICATION_JSON);
    ClientResource cr = new ClientResource(getBaseUrl());
    Representation result = cr.post(rep, MediaType.APPLICATION_JSON);
    assertTrue(cr.getStatus().isSuccess());
    assertNotNull(result);

    Response response = getResponse(MediaType.APPLICATION_JSON, result, DataSet.class);
    assertTrue(response.getSuccess());
    assertNotNull(response.getItem());

    DataSet rs = (DataSet) response.getItem();
    assertEquals(rs, item);
    RIAPUtils.exhaust(result);
    cr.release();
  }
  /**
   * Invoke an order and return the status returned
   *
   * @param urlAttach2 the url attachment of the resource
   * @return the TaskModel returned representing the status of the Task resource
   */
  protected TaskModel invokeOrder(String urlAttach2, String parameters) {
    String url = getHostUrl() + PROJECT_URL + urlAttach2 + parameters;
    Representation result = null;
    try {
      ClientResource cr = new ClientResource(url);
      ChallengeResponse chal =
          new ChallengeResponse(ChallengeScheme.HTTP_BASIC, userLogin, password);
      cr.setChallengeResponse(chal);
      result = cr.post(null, getMediaTest());
      assertNotNull(result);
      assertTrue(cr.getStatus().isSuccess());
      Response response = getResponse(getMediaTest(), result, TaskModel.class);
      assertTrue(response.getSuccess());

      return (TaskModel) response.getItem();
    } finally {
      RIAPUtils.exhaust(result);
    }
  }
  private String getServicesDescription(String parentApplicationUrl) {
    String url = parentApplicationUrl + "/services";
    System.out.println(url);
    Representation result = null;
    try {
      ClientResource cr = new ClientResource(url);
      result = cr.get(getMediaTest());
      assertNotNull(result);
      assertTrue(cr.getStatus().isSuccess());
      Response response = getResponse(getMediaTest(), result, ResourceModelDTO.class, true);
      assertTrue(response.getSuccess());
      assertNotNull(response.getData());
      assertEquals(1, response.getData().size());

      ResourceModelDTO resDTO = (ResourceModelDTO) response.getData().get(0);
      List<ResourceParameter> parameters = resDTO.getParameters();
      boolean found = false;
      String fileName = null;
      for (ResourceParameter resourceParameter : parameters) {
        if (resourceParameter.getName().equals("fileName")) {
          found = true;
          assertEquals("xs:template", resourceParameter.getValueType());
          String value = resourceParameter.getValue();
          assertFalse(value.contains("${date:"));
          fileName = resourceParameter.getValue();
          break;
        }
      }
      if (!found) {
        fail("Parameter fileName not found");
      }
      return fileName;
    } finally {
      RIAPUtils.exhaust(result);
    }
  }