예제 #1
0
  @Override
  public List<ApplicationModel> searchApplications(
      String criteria, User user, ApplicationType deviceType) {
    List<Application> applications = new ArrayList<Application>();
    if (criteria != null && !criteria.isEmpty()) {
      criteria = criteria.toLowerCase();
      List<Application> userApplications =
          userService.getApplicationsForUser(
              user,
              deviceType,
              AppState.ORGANIZATION_PUBLISH,
              AppState.GROUP_PUBLISH,
              AppState.ORG_PUBLISH_REQUEST);
      for (Application application : userApplications) {
        if ((application.getName().toLowerCase().contains(criteria)
                || application.getDescription().toLowerCase().contains(criteria))
            && !applications.contains(application)) {
          applications.add(application);
        }
      }
      ComparatorChain chain = new ComparatorChain();
      chain.addComparator(new ApplicationNameComparator());
      chain.addComparator(new ApplicationDescriptionComparator());

      Collections.sort(applications, chain);
    }

    return applicationService.createApplicationModels(applications);
  }
예제 #2
0
  @Test
  public void canUserEditApplicationTest() {
    // Initial setup
    User user = getUser();
    userService.add(user);
    Organization organization = createOrganization();
    Category category = createCategory(organization);
    organization.getCategories().add(category);
    Application application =
        createApplication(category, "Test Application", AppState.GROUP_PUBLISH);
    Group group = createGroup(organization);
    group.getOwnedApplications().add(application);

    entityManager.flush();

    createUserDomain(user, group.getId(), DomainType.GROUP, UserRole.ROLE_GROUP_ADMIN);
    entityManager.flush();

    assertTrue(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test if org admin can edit application
    user = getUser();
    userService.add(user);
    entityManager.flush();
    createUserDomain(user, organization.getId(), DomainType.ORGANIZATION, UserRole.ROLE_ORG_ADMIN);
    entityManager.flush();
    assertTrue(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test user is org user
    user = getUser();
    userService.add(user);
    entityManager.flush();
    createUserDomain(user, organization.getId(), DomainType.ORGANIZATION, UserRole.ROLE_ORG_USER);
    entityManager.flush();
    assertFalse(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test user is not part of organization and not group admin
    user = getUser();
    userService.add(user);
    entityManager.flush();
    assertFalse(userService.canUserEditApplication(user.getId(), application.getId()));
  }
예제 #3
0
  private Application createApplication(
      Category category, String applicationName, AppState appState) {
    Application application = new Application();
    application.setName(applicationName);
    application.setApplicationType(ApplicationType.ANDROID);
    application.setCategory(category);

    ApplicationVersion applicationVersion = new ApplicationVersion();
    applicationVersion.setVersionName("1.0.0");
    applicationVersion.setApplication(application);
    applicationVersion.setAppState(appState);

    application.getApplicationVersions().add(applicationVersion);

    entityManager.flush();

    return application;
  }