Exemple #1
0
  public static PracticeProp create(String client, String displayName, String login) {

    Client.ensureValid(client);
    User.ensureClientLevelPrivilege(client, login, ClientLevelPrivilege.UPDATE_PRACTICE);

    ensureNotNullNotEmpty(displayName, "displayName is null or empty");
    String name = Utils.removeSpaceUnderscoreBracketAndHyphen(displayName.toLowerCase());

    List<Key<PracticeEntity>> keys =
        ofy(client).load().type(PracticeEntity.class).filter("name", name).keys().list();

    if (keys.size() != 0)
      throw new APIException()
          .status(Status.ERROR_RESOURCE_ALREADY_EXISTS)
          .message("There is already a practice with name [" + displayName + "]");

    String key = getUniqueKey(client, name);
    long val = MemcacheServiceFactory.getMemcacheService().increment(key, 1, (long) 0);

    if (val != 1)
      throw new APIException()
          .status(Status.ERROR_RESOURCE_ALREADY_EXISTS)
          .message("There is already a group with name [" + displayName + "]");

    PracticeEntity entity = new PracticeEntity();
    entity.practiceId = Sequence.getNext(client, SequenceType.PRACTICE);
    entity.name = name;
    entity.displayName = displayName;
    ofy(client).save().entity(entity).now();

    return entity.toProp();
  }
Exemple #2
0
  public static void delete(String client, long practiceId, String login) {

    Client.ensureValid(client);
    User.ensureClientLevelPrivilege(client, login, ClientLevelPrivilege.UPDATE_PRACTICE);

    // there should not be any program type referencing this
    throw new APIException()
        .status(Status.ERROR_NOT_IMPLEMENTED)
        .message("This functionality is not implemented yet");
  }
Exemple #3
0
  public static PracticeProp rename(
      String client, long practiceId, String newDisplayName, String login) {
    Client.ensureValid(client);
    User.ensureClientLevelPrivilege(client, login, ClientLevelPrivilege.UPDATE_PRACTICE);

    PracticeEntity entity = safeGet(client, practiceId);

    ensureNotNullNotEmpty(newDisplayName, "newDisplayName is null or empty");
    String newName = Utils.removeSpaceUnderscoreBracketAndHyphen(newDisplayName.toLowerCase());

    if (entity.name.equals(newName)) {
      // ideally should be inside a transaction
      entity.displayName = newDisplayName;
      ofy(client).save().entity(entity).now();
      return entity.toProp();
    }

    List<Key<PracticeEntity>> keys =
        ofy(client).load().type(PracticeEntity.class).filter("name", newName).keys().list();
    if (keys.size() != 0)
      throw new APIException()
          .status(Status.ERROR_RESOURCE_ALREADY_EXISTS)
          .message("There is already a practice with name [" + newDisplayName + "]");

    String key = getUniqueKey(client, newName);
    long val = MemcacheServiceFactory.getMemcacheService().increment(key, 1, (long) 0);

    if (val != 1)
      throw new APIException()
          .status(Status.ERROR_RESOURCE_ALREADY_EXISTS)
          .message("There is already a practice with name [" + newDisplayName + "]");

    // ideally should be inside a transaction
    entity.name = newName;
    entity.displayName = newDisplayName;
    ofy(client).save().entity(entity).now();

    return entity.toProp();
  }