Ejemplo n.º 1
0
  @WebMethod
  @GET
  @Produces("application/json")
  @Path("/reports")
  public Response getReports(
      @QueryParam("aggregatorId") String aggregatorId,
      @QueryParam("providerId") String providerId,
      @QueryParam("productClass") String productClass)
      throws Exception {

    // Check basic permissions
    RSUser user = this.userManager.getCurrentUser();
    String effectiveAggregator;

    if (userManager.isAdmin()) {
      effectiveAggregator = aggregatorId;
    } else if (null == aggregatorId || aggregatorId.equals(user.getEmail())) {
      effectiveAggregator = user.getEmail();
    } else {
      String[] args = {"You are not allowed to retrieve report files for the given parameters"};
      throw new RSSException(UNICAExceptionType.NON_ALLOWED_OPERATION, args);
    }

    List<RSSReport> files =
        settlementManager.getSharingReports(effectiveAggregator, providerId, productClass);
    Response.ResponseBuilder rb = Response.status(Response.Status.OK.getStatusCode());
    rb.entity(files);
    return rb.build();
  }
Ejemplo n.º 2
0
  @Test
  public void getAggregatorsNotAdminTest() throws Exception {

    Aggregator aggregator = new Aggregator();
    aggregator.setAggregatorId("*****@*****.**");
    aggregator.setAggregatorName("aggregatorName");

    RSUser user = new RSUser();
    user.setEmail("*****@*****.**");

    when(userManager.isAdmin()).thenReturn(false);
    when(userManager.getCurrentUser()).thenReturn(user);
    when(aggregatorManager.getAggregator("*****@*****.**")).thenReturn(aggregator);

    Response response = toTest.getAggregators();

    Assert.assertEquals(200, response.getStatus());
    List listResponse = (List) response.getEntity();
    Assert.assertEquals(aggregator, listResponse.get(0));
  }
  private void mockUserRoles(String... roles) {
    Set<Role> rolesSet = new HashSet<>();

    for (String role : roles) {
      Role r = new Role();
      r.setId(role);
      r.setName(role);
      rolesSet.add(r);
    }
    user.setRoles(rolesSet);

    when(userDaoMock.getCurrentUser()).thenReturn(user);
  }
Ejemplo n.º 4
0
  @WebMethod
  @GET
  public Response launchSettlement(
      @QueryParam("aggregatorId") String aggregatorId,
      @QueryParam("providerId") String providerId,
      @QueryParam("productClass") String productClass)
      throws Exception {

    // Check basic permissions
    RSUser user = this.userManager.getCurrentUser();
    if (!this.userManager.isAdmin()
        && (aggregatorId == null || !user.getEmail().equalsIgnoreCase(aggregatorId))) {

      String[] args = {
        "You are not allowed to launch the settlement process for the given parameters"
      };
      throw new RSSException(UNICAExceptionType.NON_ALLOWED_OPERATION, args);
    }

    // Launch process
    settlementManager.runSettlement(aggregatorId, providerId, productClass);
    Response.ResponseBuilder rb = Response.status(Response.Status.ACCEPTED.getStatusCode());
    return rb.build();
  }