示例#1
0
  public ServiceResults updateApplicationEntity(ServicePayload payload) throws Exception {

    Map<String, Object> properties = payload.getProperties();
    Object m = properties.get("metadata");
    if (m instanceof Map) {
      @SuppressWarnings("unchecked")
      Map<String, Object> metadata = (Map<String, Object>) m;
      Object c = metadata.get("collections");
      if (c instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<String, Object> collections = (Map<String, Object>) c;
        for (String collection : collections.keySet()) {
          em.createApplicationCollection(collection);
          logger.info(
              "Created collection " + collection + " for application " + sm.getApplicationId());
        }
      }
    }

    Entity entity = em.get(em.getApplicationRef());
    em.updateProperties(entity, properties);
    entity.addProperties(properties);
    Results r = Results.fromEntity(entity);

    Set<String> collections = em.getApplicationCollections();
    if (collections.size() > 0) {
      r.setMetadata(em.getApplicationRef().getUuid(), "collections", collections);
    }

    return genericServiceResults(r);
  }
示例#2
0
  @Override
  public ServiceResults postEntityDictionary(
      ServiceContext context, List<EntityRef> refs, String dictionary, ServicePayload payload)
      throws Exception {
    if ("rolenames".equalsIgnoreCase(dictionary)) {

      if (context.parameterCount() == 1) {

        String name = payload.getStringProperty("name");
        if (isBlank(name)) {
          return null;
        }

        String title = payload.getStringProperty("title");
        if (isBlank(title)) {
          title = name;
        }

        return newApplicationRole(name, title);

      } else if (context.parameterCount() == 2) {

        String roleName = context.getParameters().get(1).getName();
        if (isBlank(roleName)) {
          return null;
        }

        String permission = payload.getStringProperty("permission");
        if (isBlank(permission)) {
          return null;
        }

        return grantApplicationRolePermission(roleName, permission);
      }
    }

    return super.postEntityDictionary(context, refs, dictionary, payload);
  }
  @Override
  public ServiceResults postEntityDictionary(
      ServiceContext context, List<EntityRef> refs, String dictionary, ServicePayload payload)
      throws Exception {

    if ("permissions".equalsIgnoreCase(dictionary)) {
      EntityRef entityRef = refs.get(0);
      checkPermissionsForEntitySubPath(context, entityRef, "permissions");

      String permission = payload.getStringProperty("permission");
      if (isBlank(permission)) {
        return null;
      }

      em.grantUserPermission(entityRef.getUuid(), permission);

      return genericServiceResults().withData(em.getUserPermissions(entityRef.getUuid()));
    }

    return super.postEntityDictionary(context, refs, dictionary, payload);
  }
  @Override
  public ServiceResults putEntityDictionary(
      ServiceContext context, List<EntityRef> refs, String dictionary, ServicePayload payload)
      throws Exception {

    if ("rolenames".equalsIgnoreCase(dictionary)) {
      EntityRef entityRef = refs.get(0);
      checkPermissionsForEntitySubPath(context, entityRef, "rolenames");

      if (context.parameterCount() == 0) {

        String name = payload.getStringProperty("name");
        if (isBlank(name)) {
          return null;
        }

        return addUserRole(entityRef.getUuid(), name);
      }
    }

    return super.postEntityDictionary(context, refs, dictionary, payload);
  }