Esempio n. 1
0
  @Override
  public ApplicationInfo createSampleFor(OrganizationInfo organizationInfo)
      throws ApplicationCreationException {

    Preconditions.checkArgument(organizationInfo != null, "OrganizationInfo was null");
    Preconditions.checkArgument(organizationInfo.getUuid() != null, "OrganizationInfo had no UUID");
    logger.info("create sample app {} in: {}", sampleAppName, organizationInfo.getName());
    UUID appId = null;
    try {
      appId =
          managementService.createApplication(organizationInfo.getUuid(), sampleAppName).getId();
    } catch (Exception ex) {
      throw new ApplicationCreationException(
          "'"
              + sampleAppName
              + "' could not be created for organization: "
              + organizationInfo.getUuid(),
          ex);
    }
    logger.info("granting permissions for: {} in: {}", sampleAppName, organizationInfo.getName());
    // grant access to all default collections with groups
    EntityManager em = entityManagerFactory.getEntityManager(appId);
    try {
      em.grantRolePermissions("guest", Arrays.asList("get,post,put,delete:/**"));
      em.grantRolePermissions("default", Arrays.asList("get,put,post,delete:/**"));
    } catch (Exception ex) {
      throw new ApplicationCreationException(
          "Could not grant permissions to guest for default collections in '" + sampleAppName + "'",
          ex);
    }
    // re-load the applicationinfo so the correct name is set
    try {
      return managementService.getApplicationInfo(appId);
    } catch (Exception ex) {
      throw new ApplicationCreationException("Could not load new Application.", ex);
    }
  }
Esempio n. 2
0
  /** @return Map of Organization UUID -> Name */
  private Map<UUID, String> getOrganizations() throws Exception {

    Map<UUID, String> organizationNames;

    if (orgId == null) {
      organizationNames = managementService.getOrganizations();
    } else {

      OrganizationInfo info = managementService.getOrganizationByUuid(orgId);

      if (info == null) {
        LOG.error("Organization info is null!");
        System.exit(1);
      }

      organizationNames = new HashMap<UUID, String>();
      organizationNames.put(orgId, info.getName());
    }

    return organizationNames;
  }