Exemplo n.º 1
0
  /** Tests the details retrieval. */
  @Test
  public final void testTaskDetails() {
    Task newTask = TestDataIT.createTask();
    newTask.setApplicationId(apps.get((int) (Math.random() * apps.size())));
    Response rs;
    rs =
        target("/v1.0/tasks")
            .request(Constants.INDIGOMIMETYPE)
            .post(Entity.entity(newTask, Constants.INDIGOMIMETYPE));
    rs =
        target("/v1.0/tasks/" + rs.readEntity(Application.class).getId())
            .request(Constants.INDIGOMIMETYPE)
            .get();

    Assert.assertEquals(Response.Status.OK.getStatusCode(), rs.getStatus());
    Task task = rs.readEntity(Task.class);
    Assert.assertNotNull(task);
    Assert.assertNotNull(task.getId());
    Assert.assertNotNull(task.getDateCreated());
    Assert.assertNotNull(task.getLastChange());
    Assert.assertEquals(newTask.getDescription(), task.getDescription());
    Assert.assertEquals(newTask.getApplicationId(), task.getApplicationId());
    Transformer<TaskFile, String> transformer =
        new Transformer<TaskFile, String>() {
          @Override
          public String transform(final TaskFile file) {
            return file.getName();
          }
        };
    if (newTask.getInputFiles() != null) {
      Assert.assertNotNull(task.getInputFiles());
      Assert.assertEquals(
          IterableUtils.toString(newTask.getInputFiles(), transformer),
          IterableUtils.toString(task.getInputFiles(), transformer));
    }
    if (newTask.getOutputFiles() != null) {
      Assert.assertNotNull(task.getOutputFiles());
      Assert.assertEquals(
          IterableUtils.toString(newTask.getOutputFiles(), transformer),
          IterableUtils.toString(task.getOutputFiles(), transformer));
    }
    target("/v1.0/tasks/" + task.getId()).request().delete();
  }
  /**
   * @param method the method
   * @param searchTopMethod search for top most overridden method
   * @return the corresponding element name
   */
  public static String getElementName(Method method, boolean searchTopMethod) {
    Method topMethod = method;

    if (searchTopMethod) {
      // Get top most method declaration
      Set<Method> hierarchy = MethodUtils.getOverrideHierarchy(method, Interfaces.INCLUDE);
      topMethod = IterableUtils.get(hierarchy, hierarchy.size() - 1);
    }

    // Get element name from method
    return getElementName(topMethod);
  }
Exemplo n.º 3
0
  protected static ConnBundleTO getBundle(
      final ConnInstanceTO connInstanceTO, final List<ConnBundleTO> bundles) {
    return IterableUtils.find(
        bundles,
        new Predicate<ConnBundleTO>() {

          @Override
          public boolean evaluate(final ConnBundleTO bundle) {
            return bundle.getBundleName().equals(connInstanceTO.getBundleName())
                && bundle.getVersion().equals(connInstanceTO.getVersion());
          }
        });
  }
Exemplo n.º 4
0
  protected NotificationTaskTO findNotificationTaskBySender(final String sender) {
    PagedResult<NotificationTaskTO> tasks =
        taskService.list(new TaskQuery.Builder().type(TaskType.NOTIFICATION).build());
    assertNotNull(tasks);
    assertFalse(tasks.getResult().isEmpty());

    return IterableUtils.find(
        tasks.getResult(),
        new Predicate<NotificationTaskTO>() {

          @Override
          public boolean evaluate(final NotificationTaskTO task) {
            return sender.equals(task.getSender());
          }
        });
  }
Exemplo n.º 5
0
  @Override
  protected void securityChecks(final User user) {
    // Allows anonymous (during self-registration) and self (during self-update) to read own user,
    // otherwise goes through security checks to see if required entitlements are owned
    if (!AuthContextUtils.getUsername().equals(anonymousUser)
        && !AuthContextUtils.getUsername().equals(user.getUsername())) {

      Set<String> authRealms =
          AuthContextUtils.getAuthorizations().get(StandardEntitlement.USER_READ);
      boolean authorized =
          IterableUtils.matchesAny(
              authRealms,
              new Predicate<String>() {

                @Override
                public boolean evaluate(final String realm) {
                  return user.getRealm().getFullPath().startsWith(realm);
                }
              });
      if (authRealms == null || authRealms.isEmpty() || !authorized) {
        throw new DelegatedAdministrationException(AnyTypeKind.USER, user.getKey());
      }
    }
  }
  /**
   * @param type the class of the filter
   * @return the descriptor of the filter
   * @throws IncompatibleFilterException when several methods/events are incompatibles
   */
  private FilterDescriptor createDescriptor(Class<?> type) throws IncompatibleFilterException {
    // Proxy "loose" various reflection informations (like method parameter names)
    if (Proxy.isProxyClass(type)) {
      return getFilterDescriptor(type.getInterfaces());
    } else {
      FilterDescriptor descriptor = new FilterDescriptor();

      for (Method method : type.getMethods()) {
        // Get top most method declaration
        Set<Method> hierarchy = MethodUtils.getOverrideHierarchy(method, Interfaces.INCLUDE);
        Method topMethod = IterableUtils.get(hierarchy, hierarchy.size() - 1);

        // Get element name from method
        String elementName = getElementName(topMethod);

        // If a name can be found, continue
        if (elementName != null) {
          addElement(elementName, descriptor, topMethod);
        }
      }

      return descriptor;
    }
  }