Beispiel #1
0
  @Override
  public TagType createTagType(TagTypeCreateRequest request) {
    // Validate and trim the request parameters.
    validateTagTypeCreateRequest(request);

    // Validate the tag type does not already exist in the database.
    TagTypeEntity tagTypeEntity = tagTypeDao.getTagTypeByKey(request.getTagTypeKey());
    if (tagTypeEntity != null) {
      throw new AlreadyExistsException(
          String.format(
              "Unable to create tag type with code \"%s\" because it already exists.",
              request.getTagTypeKey().getTagTypeCode()));
    }

    // Validate the display name does not already exist in the database
    tagTypeDaoHelper.assertTagTypeDisplayNameDoesNotExist(request.getDisplayName());

    // Create and persist a new tag type entity from the request information.
    tagTypeEntity =
        createTagTypeEntity(
            request.getTagTypeKey().getTagTypeCode(),
            request.getDisplayName(),
            request.getTagTypeOrder());

    // Create and return the tag type object from the persisted entity.
    return createTagTypeFromEntity(tagTypeEntity);
  }
Beispiel #2
0
  @Override
  public TagType getTagType(TagTypeKey tagTypeKey) {
    // Perform validation and trim.
    tagTypeHelper.validateTagTypeKey(tagTypeKey);

    // Retrieve and ensure that a tag type already exists with the specified key.
    TagTypeEntity tagTypeEntity = tagTypeDaoHelper.getTagTypeEntity(tagTypeKey);

    // Create and return the tag type object from the persisted entity.
    return createTagTypeFromEntity(tagTypeEntity);
  }
Beispiel #3
0
  @Override
  public TagType updateTagType(TagTypeKey tagTypeKey, TagTypeUpdateRequest request) {
    // Perform validation and trim.
    tagTypeHelper.validateTagTypeKey(tagTypeKey);

    // Perform validation and trim the alternate key parameters.
    validateTagTypeUpdateRequest(request);

    // Retrieve and ensure that a tag type already exists with the specified key.
    TagTypeEntity tagTypeEntity = tagTypeDaoHelper.getTagTypeEntity(tagTypeKey);

    // Validate the display name does not already exist for another tag type.
    if (!StringUtils.equalsIgnoreCase(tagTypeEntity.getDisplayName(), request.getDisplayName())) {
      // Validate that the description is different.
      tagTypeDaoHelper.assertTagTypeDisplayNameDoesNotExist(request.getDisplayName());
    }

    // Update and persist the tag type entity.
    updateTagTypeEntity(tagTypeEntity, request);

    // Create and return the tag type from the persisted entity.
    return createTagTypeFromEntity(tagTypeEntity);
  }