Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/description field #133

Merged
merged 11 commits into from
Feb 8, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public class ResourceCreationDto {
@Schema(description = "Description of the path parameter: example/path",
pattern = "(^$)|(^(?!/)[a-zA-Z0-9/]+(?<!/)$)")
private String path;
@FormParam("description")
private String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package it.gov.pagopa.atmlayer.service.model.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import it.gov.pagopa.atmlayer.service.model.enumeration.UserProfileEnum;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

import java.sql.Timestamp;

@NoArgsConstructor
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserProfileAllDto {
@Schema(example = "[email protected]")
private String userId;
private UserProfileEnum profile;
@Schema(example = "2024-02-07T11:38:58.445+00:00")
private Timestamp createdAt;
@Schema(example = "2024-02-07T11:38:58.445+00:00")
private Timestamp lastUpdatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package it.gov.pagopa.atmlayer.service.model.dto;

import it.gov.pagopa.atmlayer.service.model.enumeration.UserProfileEnum;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

import java.sql.Timestamp;

@NoArgsConstructor
@Data
public class UserProfileCreationDto {

@NotNull(message = "is required")
@Email(message = "must be an email address in the correct format")
@Schema(required = true, example = "[email protected]")
private String userId;
@NotNull(message = "is required")
@Schema(required = true, description = "1 = GUEST, 2 = OPERATOR, 3 = ADMIN")
private Integer profile;
@Schema(hidden = true)
private Timestamp createdAt;
@Schema(hidden = true)
private Timestamp lastUpdatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package it.gov.pagopa.atmlayer.service.model.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import it.gov.pagopa.atmlayer.service.model.enumeration.UserProfileEnum;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

import java.sql.Timestamp;

@NoArgsConstructor
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserProfileDto {
@Schema(example = "[email protected]")
private String userId;
private UserProfileEnum profile;
private Boolean visible;
private Boolean editable;
private Boolean admin;
@Schema(example = "2024-02-07T11:38:58.445+00:00")
private Timestamp createdAt;
@Schema(example = "2024-02-07T11:38:58.445+00:00")
private Timestamp lastUpdatedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class ResourceEntity extends PanacheEntityBase implements Serializable {
@Transient
@Getter(AccessLevel.NONE)
private String cdnUrl;
@Column(name = "description")
private String description;

@PrePersist
public void generateUUID() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package it.gov.pagopa.atmlayer.service.model.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.sql.Timestamp;

@Entity
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "user_profile")
public class UserProfile {
@Id
@Column(name = "user_id")
private String userId;
@Column(name = "profile")
private int profile;
@CreationTimestamp
@Column(name = "created_at")
private Timestamp createdAt;
@UpdateTimestamp
@Column(name = "last_updated_at")
private Timestamp lastUpdatedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public enum AppErrorCodeEnum {
BPMN_ALREADY_DISABLED("ATMLM_4000039", "The referenced BPMN file is already disabled", CANNOT_DISABLE),
DUPLICATE_ASSOCIATION_CONFIGS("ATMLM_4000040","Cannot save associations: duplicate configurations in input",CANNOT_ASSOCIATE),
PAGE_SIZE_WRONG_VALUE("ATMLM_4000041", "Page and Size must not be null or empty, and Size greater than zero", INVALID_ARGUMENT),
ILLEGALE_CONFIGURATION_TRIPLET("ATMLM_4000042","AcquirerId must be specified for BranchId, and BranchId must be specified for TerminalId",INVALID_ARGUMENT);
ILLEGALE_CONFIGURATION_TRIPLET("ATMLM_4000042","AcquirerId must be specified for BranchId, and BranchId must be specified for TerminalId",INVALID_ARGUMENT),
USER_PROFILE_WITH_SAME_ID_ALREADY_EXIST("ATMLM_4000043", "A User Profile with the same id already exists", CONSTRAINT_VIOLATION),
NO_USER_PROFILE_FOUND_FOR_ID("ATMLM_4000044", "No User found for id", NOT_EXISTING_USER_ID),
NO_USER_PROFILE_FOUND_FOR_PROFILE("ATMLM_4000045", "No User profile found", NOT_EXISTING_USER_PROFILE);
private final String errorCode;
private final String errorMessage;
private final AppErrorType type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ public enum AppErrorType {
NOT_UPLOADABLE,
CANNOT_ROLLBACK,
CANNOT_DISABLE,
CANNOT_ASSOCIATE
CANNOT_ASSOCIATE,
NOT_EXISTING_USER_ID,
NOT_EXISTING_USER_PROFILE,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package it.gov.pagopa.atmlayer.service.model.enumeration;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@AllArgsConstructor
@Getter
public enum UserProfileEnum {
GUEST(1),
OPERATOR(2),
ADMIN(3);

private final int value;
private static final Map<Integer, UserProfileEnum> map = new HashMap<>();

static {
for (UserProfileEnum profileEnum : UserProfileEnum.values()) {
map.put(profileEnum.value, profileEnum);
}
}

public static UserProfileEnum valueOf(int profile) {
return map.get(profile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public ResourceEntity toEntityCreation(ResourceCreationDto resourceCreationDto)
resourceEntity.setStorageKey(resourceEntityStorageService.calculateStorageKey(
resourceCreationDto.getResourceType(),resourceCreationDto.getPath(),resourceCreationDto.getFilename()
));
resourceEntity.setDescription(resourceCreationDto.getDescription());
return resourceEntity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile;
import it.gov.pagopa.atmlayer.service.model.model.ResourceFileDTO;
import it.gov.pagopa.atmlayer.service.model.model.ResourceFrontEndDTO;
import org.mapstruct.IterableMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.List;

@Mapper(componentModel = "cdi")
public interface ResourceFileMapper {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package it.gov.pagopa.atmlayer.service.model.mapper;

import it.gov.pagopa.atmlayer.service.model.dto.UserProfileAllDto;
import it.gov.pagopa.atmlayer.service.model.dto.UserProfileCreationDto;
import it.gov.pagopa.atmlayer.service.model.dto.UserProfileDto;
import it.gov.pagopa.atmlayer.service.model.entity.UserProfile;
import it.gov.pagopa.atmlayer.service.model.enumeration.UserProfileEnum;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValuePropertyMappingStrategy;

import java.util.List;

@Mapper(componentModel = "cdi", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public abstract class UserProfileMapper {

@Mapping(source = "userProfile.userId", target = "userId")
@Mapping(expression = "java(getEnumValue(userProfile.getProfile()))", target = "profile")
@Mapping(source = "userProfile.createdAt", target = "createdAt")
@Mapping(source = "userProfile.lastUpdatedAt", target = "lastUpdatedAt")
public abstract UserProfileDto toUserProfileDto(UserProfile userProfile);

@Mapping(source = "userProfile.userId", target = "userId")
@Mapping(expression = "java(getEnumValue(userProfile.getProfile()))", target = "profile")
@Mapping(source = "userProfile.createdAt", target = "createdAt")
@Mapping(source = "userProfile.lastUpdatedAt", target = "lastUpdatedAt")
public abstract UserProfileAllDto toUserProfileAllDto(UserProfile userProfile);

@Mapping(source = "userProfile.userId", target = "userId")
@Mapping(source = "userProfile.profile", target = "profile")
@Mapping(source = "userProfile.createdAt", target = "createdAt")
@Mapping(source = "userProfile.lastUpdatedAt", target = "lastUpdatedAt")
public abstract UserProfile toUserProfile(UserProfileCreationDto userProfile);

UserProfileEnum getEnumValue(int source) {
return UserProfileEnum.valueOf(source);
}

public UserProfileDto toUserProfileDtoWithProfileMapping(UserProfile userProfile) {
UserProfileDto userProfileDTO = this.toUserProfileDto(userProfile);
switch(UserProfileEnum.valueOf(userProfile.getProfile())){
case GUEST -> {
userProfileDTO.setVisible(true);
userProfileDTO.setEditable(false);
userProfileDTO.setAdmin(false);
}
case OPERATOR -> {
userProfileDTO.setVisible(true);
userProfileDTO.setEditable(true);
userProfileDTO.setAdmin(false);
}
case ADMIN -> {
userProfileDTO.setVisible(true);
userProfileDTO.setEditable(true);
userProfileDTO.setAdmin(true);
}
}
return userProfileDTO;
}

public List<UserProfileDto> toDtoList(List<UserProfile> list){
return list.stream().map( x -> this.toUserProfileDto(x)).toList();
}

public List<UserProfileAllDto> toDtoAllList(List<UserProfile> list){
return list.stream().map( x -> this.toUserProfileAllDto(x)).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class ResourceDTO {
private String lastUpdatedBy;
private String cdnUrl;
private ResourceFileDTO resourceFile;
private String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package it.gov.pagopa.atmlayer.service.model.repository;

import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
import io.smallrye.mutiny.Uni;
import it.gov.pagopa.atmlayer.service.model.entity.UserProfile;
import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class UserProfileRepository implements PanacheRepositoryBase<UserProfile, String> {
public Uni<UserProfile> findUserId(String userId) {
return find("userId", userId).firstResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Uni<ResourceDTO> createResource(
throws NoSuchAlgorithmException, IOException {
ResourceEntity resourceEntity = resourceEntityMapper.toEntityCreation(resourceCreationDto);
return resourceEntityService.createResource(resourceEntity, resourceCreationDto.getFile(),
resourceCreationDto.getFilename(), resourceCreationDto.getPath())
resourceCreationDto.getFilename(), resourceCreationDto.getPath(), resourceCreationDto.getDescription())
.onItem()
.transformToUni(resource -> Uni.createFrom().item(resourceEntityMapper.toDTO(resource)));
}
Expand Down Expand Up @@ -102,9 +102,9 @@ public Uni<ResourceDTO> getById(@PathParam("uuid") UUID uuid) {
@Path("/filter")
@Produces(MediaType.APPLICATION_JSON)
public Uni<PageInfo<ResourceFrontEndDTO>> getResourceFiltered(@QueryParam("pageIndex") @DefaultValue("0")
@Parameter(required = true, schema = @Schema(type = SchemaType.INTEGER, minimum = "0")) int pageIndex,
@Parameter(required = true, schema = @Schema(type = SchemaType.INTEGER, minimum = "0")) int pageIndex,
@QueryParam("pageSize") @DefaultValue("10")
@Parameter(required = true, schema = @Schema(type = SchemaType.INTEGER, minimum = "1")) int pageSize,
@Parameter(required = true, schema = @Schema(type = SchemaType.INTEGER, minimum = "1")) int pageSize,
@QueryParam("resourceId") UUID resourceId,
@QueryParam("sha256") String sha256,
@QueryParam("noDeployableResourceType") NoDeployableResourceType noDeployableResourceType,
Expand All @@ -122,3 +122,4 @@ public Uni<PageInfo<ResourceFrontEndDTO>> getResourceFiltered(@QueryParam("pageI
}));
}
}

Loading
Loading