| @@ -1,125 +1,125 @@ | |||
| package vn.azteam.tpf.domain; | |||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |||
| import org.hibernate.annotations.Cache; | |||
| import org.hibernate.annotations.CacheConcurrencyStrategy; | |||
| import org.springframework.data.elasticsearch.annotations.Document; | |||
| import javax.persistence.*; | |||
| import java.io.Serializable; | |||
| import java.time.Instant; | |||
| @Entity | |||
| @Table(name = "tb_product_label") | |||
| @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) | |||
| @Document(indexName = "smf_tbproductlabel") | |||
| public class TBProductLabel implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |||
| private Long id; | |||
| @Column(name = "media") | |||
| private String media; | |||
| @Column(name = "description") | |||
| private String description; | |||
| @Column(name = "created_date") | |||
| private Instant createdDate; | |||
| @Column(name = "modified_date") | |||
| private Instant modifiedDate; | |||
| @Column(name = "deleted_date") | |||
| private Instant deletedDate; | |||
| @ManyToOne(fetch = FetchType.LAZY) | |||
| @JsonIgnoreProperties("") | |||
| @JoinColumn(name = "created_by") | |||
| private TBDetailUser createdBy; | |||
| @ManyToOne(fetch = FetchType.LAZY) | |||
| @JsonIgnoreProperties("") | |||
| @JoinColumn(name = "modified_by") | |||
| private TBDetailUser modifiedBy; | |||
| @ManyToOne(fetch = FetchType.LAZY) | |||
| @JsonIgnoreProperties("") | |||
| @JoinColumn(name = "deleted_by") | |||
| private TBDetailUser deletedBy; | |||
| public Long getId() { | |||
| return id; | |||
| } | |||
| public void setId(Long id) { | |||
| this.id = id; | |||
| } | |||
| public String getMedia() { | |||
| return media; | |||
| } | |||
| public void setMedia(String media) { | |||
| this.media = media; | |||
| } | |||
| public String getDescription() { | |||
| return description; | |||
| } | |||
| public void setDescription(String description) { | |||
| this.description = description; | |||
| } | |||
| public Instant getCreatedDate() { | |||
| return createdDate; | |||
| } | |||
| public void setCreatedDate(Instant createdDate) { | |||
| this.createdDate = createdDate; | |||
| } | |||
| public Instant getModifiedDate() { | |||
| return modifiedDate; | |||
| } | |||
| public void setModifiedDate(Instant modifiedDate) { | |||
| this.modifiedDate = modifiedDate; | |||
| } | |||
| public Instant getDeletedDate() { | |||
| return deletedDate; | |||
| } | |||
| public void setDeletedDate(Instant deletedDate) { | |||
| this.deletedDate = deletedDate; | |||
| } | |||
| public TBDetailUser getCreatedBy() { | |||
| return createdBy; | |||
| } | |||
| public void setCreatedBy(TBDetailUser createdBy) { | |||
| this.createdBy = createdBy; | |||
| } | |||
| public TBDetailUser getModifiedBy() { | |||
| return modifiedBy; | |||
| } | |||
| public void setModifiedBy(TBDetailUser modifiedBy) { | |||
| this.modifiedBy = modifiedBy; | |||
| } | |||
| public TBDetailUser getDeletedBy() { | |||
| return deletedBy; | |||
| } | |||
| public void setDeletedBy(TBDetailUser deletedBy) { | |||
| this.deletedBy = deletedBy; | |||
| } | |||
| } | |||
| //package vn.azteam.tpf.domain; | |||
| // | |||
| //import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |||
| //import org.hibernate.annotations.Cache; | |||
| //import org.hibernate.annotations.CacheConcurrencyStrategy; | |||
| //import org.springframework.data.elasticsearch.annotations.Document; | |||
| // | |||
| //import javax.persistence.*; | |||
| //import java.io.Serializable; | |||
| //import java.time.Instant; | |||
| // | |||
| //@Entity | |||
| //@Table(name = "tb_product_label") | |||
| //@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) | |||
| //@Document(indexName = "smf_tbproductlabel") | |||
| //public class TBProductLabel implements Serializable { | |||
| // | |||
| // private static final long serialVersionUID = 1L; | |||
| // | |||
| // @Id | |||
| // @GeneratedValue(strategy = GenerationType.IDENTITY) | |||
| // private Long id; | |||
| // | |||
| // @Column(name = "media") | |||
| // private String media; | |||
| // | |||
| // @Column(name = "description") | |||
| // private String description; | |||
| // | |||
| // @Column(name = "created_date") | |||
| // private Instant createdDate; | |||
| // | |||
| // @Column(name = "modified_date") | |||
| // private Instant modifiedDate; | |||
| // | |||
| // @Column(name = "deleted_date") | |||
| // private Instant deletedDate; | |||
| // | |||
| // @ManyToOne(fetch = FetchType.LAZY) | |||
| // @JsonIgnoreProperties("") | |||
| // @JoinColumn(name = "created_by") | |||
| // private TBDetailUser createdBy; | |||
| // | |||
| // @ManyToOne(fetch = FetchType.LAZY) | |||
| // @JsonIgnoreProperties("") | |||
| // @JoinColumn(name = "modified_by") | |||
| // private TBDetailUser modifiedBy; | |||
| // | |||
| // @ManyToOne(fetch = FetchType.LAZY) | |||
| // @JsonIgnoreProperties("") | |||
| // @JoinColumn(name = "deleted_by") | |||
| // private TBDetailUser deletedBy; | |||
| // | |||
| // public Long getId() { | |||
| // return id; | |||
| // } | |||
| // | |||
| // public void setId(Long id) { | |||
| // this.id = id; | |||
| // } | |||
| // | |||
| // public String getMedia() { | |||
| // return media; | |||
| // } | |||
| // | |||
| // public void setMedia(String media) { | |||
| // this.media = media; | |||
| // } | |||
| // | |||
| // public String getDescription() { | |||
| // return description; | |||
| // } | |||
| // | |||
| // public void setDescription(String description) { | |||
| // this.description = description; | |||
| // } | |||
| // | |||
| // public Instant getCreatedDate() { | |||
| // return createdDate; | |||
| // } | |||
| // | |||
| // public void setCreatedDate(Instant createdDate) { | |||
| // this.createdDate = createdDate; | |||
| // } | |||
| // | |||
| // public Instant getModifiedDate() { | |||
| // return modifiedDate; | |||
| // } | |||
| // | |||
| // public void setModifiedDate(Instant modifiedDate) { | |||
| // this.modifiedDate = modifiedDate; | |||
| // } | |||
| // | |||
| // public Instant getDeletedDate() { | |||
| // return deletedDate; | |||
| // } | |||
| // | |||
| // public void setDeletedDate(Instant deletedDate) { | |||
| // this.deletedDate = deletedDate; | |||
| // } | |||
| // | |||
| // public TBDetailUser getCreatedBy() { | |||
| // return createdBy; | |||
| // } | |||
| // | |||
| // public void setCreatedBy(TBDetailUser createdBy) { | |||
| // this.createdBy = createdBy; | |||
| // } | |||
| // | |||
| // public TBDetailUser getModifiedBy() { | |||
| // return modifiedBy; | |||
| // } | |||
| // | |||
| // public void setModifiedBy(TBDetailUser modifiedBy) { | |||
| // this.modifiedBy = modifiedBy; | |||
| // } | |||
| // | |||
| // public TBDetailUser getDeletedBy() { | |||
| // return deletedBy; | |||
| // } | |||
| // | |||
| // public void setDeletedBy(TBDetailUser deletedBy) { | |||
| // this.deletedBy = deletedBy; | |||
| // } | |||
| //} | |||
| @@ -1,12 +1,12 @@ | |||
| package vn.azteam.tpf.repository; | |||
| import org.springframework.data.jpa.repository.JpaRepository; | |||
| import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | |||
| import org.springframework.stereotype.Repository; | |||
| import vn.azteam.tpf.domain.TBProductLabel; | |||
| // | |||
| //import org.springframework.data.jpa.repository.JpaRepository; | |||
| //import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | |||
| //import org.springframework.stereotype.Repository; | |||
| //import vn.azteam.tpf.domain.TBProductLabel; | |||
| //@Repository | |||
| public interface TBProductLabelRepository extends JpaRepository<TBProductLabel, Long>, JpaSpecificationExecutor<TBProductLabel> { | |||
| } | |||
| //public interface TBProductLabelRepository extends JpaRepository<TBProductLabel, Long>, JpaSpecificationExecutor<TBProductLabel> { | |||
| // | |||
| // | |||
| //} | |||
| @@ -6,11 +6,9 @@ import org.springframework.security.core.context.SecurityContextHolder; | |||
| import org.springframework.security.core.userdetails.UserDetails; | |||
| import org.springframework.util.StringUtils; | |||
| import org.springframework.web.filter.GenericFilterBean; | |||
| import vn.azteam.tpf.security.AuthoritiesConstants; | |||
| import vn.azteam.tpf.security.apiKey.ApiKeyProvider; | |||
| import vn.azteam.tpf.service.TBPermissionQueryService; | |||
| import vn.azteam.tpf.service.UserService; | |||
| import vn.azteam.tpf.service.dto.TBPermissionDTO; | |||
| import vn.azteam.tpf.service.dto.UserDTO; | |||
| import javax.servlet.FilterChain; | |||
| @@ -22,7 +20,10 @@ import javax.servlet.http.HttpServletResponse; | |||
| import java.io.IOException; | |||
| import java.security.InvalidKeyException; | |||
| import java.security.NoSuchAlgorithmException; | |||
| import java.util.*; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| import static vn.azteam.tpf.security.contants.Contants.*; | |||
| @@ -50,6 +51,7 @@ public class AuthzFilter extends GenericFilterBean { | |||
| "/api/update-common-activity-guideline-details/", | |||
| "/api/delete-common-activity-guideline-details/", | |||
| "/api/tb-customers-api-key", | |||
| "/api/tb-code-details/scan/", | |||
| "/api/notification/update-person-in-charge")); | |||
| List<String> whiteListWithGetMethod = new ArrayList<>( | |||
| @@ -128,7 +130,7 @@ public class AuthzFilter extends GenericFilterBean { | |||
| "/api/list-supplies-in-warehouses", | |||
| "/api/tb-activity-types-dropdown-list", | |||
| "/api/tb-activity-types-dropdown-list-after-harvest", | |||
| "/api/tb-product-label/dropdown-list", | |||
| "/api/tb-example-stamp/dropdown-list", | |||
| "/api/display-object-param-dynamic-form-guideline-details/", | |||
| "/api/display-object-param-dynamic-form", | |||
| "/api/tb-dashboard-types", | |||
| @@ -154,7 +156,7 @@ public class AuthzFilter extends GenericFilterBean { | |||
| Arrays.asList()); | |||
| private final UserService userService; | |||
| private final TBPermissionQueryService tbPermissionQueryService ; | |||
| private final TBPermissionQueryService tbPermissionQueryService; | |||
| private final Enforcer enforcer; | |||
| private final ApiKeyProvider apiKeyProvider; | |||
| @@ -173,40 +175,40 @@ public class AuthzFilter extends GenericFilterBean { | |||
| String requestMethod = request.getMethod(); | |||
| // Allows URLs that not starts with the /api/ prefix. | |||
| if(!requestPath.startsWith(tpf_API_PREFIX)){ | |||
| if (!requestPath.startsWith(tpf_API_PREFIX)) { | |||
| filterChain.doFilter(request, response); | |||
| return; | |||
| } | |||
| // URLs are allowed by anyone | |||
| for (String path : whiteList){ | |||
| if(requestPath.startsWith(path)){ | |||
| for (String path : whiteList) { | |||
| if (requestPath.startsWith(path)) { | |||
| filterChain.doFilter(request, response); | |||
| return; | |||
| } | |||
| } | |||
| // URLs are allowed by anyone with GET request | |||
| if(requestMethod.equals(GET_REQUEST_METHOD)){ | |||
| for (String path : whiteListWithGetMethod){ | |||
| if(requestPath.startsWith(path)){ | |||
| if (requestMethod.equals(GET_REQUEST_METHOD)) { | |||
| for (String path : whiteListWithGetMethod) { | |||
| if (requestPath.startsWith(path)) { | |||
| filterChain.doFilter(request, response); | |||
| return; | |||
| } | |||
| } | |||
| } | |||
| // URLs are allowed by apiKey with GET & NON-GET request | |||
| if(requestPath.startsWith(OTS_API_PREFIX)){ | |||
| if (requestPath.startsWith(OTS_API_PREFIX)) { | |||
| try { | |||
| if (this.apiKeyHasPermission(request)) { | |||
| for (String path : apiKeyListWithGetMethod){ | |||
| if(requestPath.startsWith(path)){ | |||
| for (String path : apiKeyListWithGetMethod) { | |||
| if (requestPath.startsWith(path)) { | |||
| filterChain.doFilter(request, response); | |||
| return; | |||
| } | |||
| } | |||
| for (String path : apiKeyListNonGetMethod){ | |||
| if(requestPath.startsWith(path)){ | |||
| for (String path : apiKeyListNonGetMethod) { | |||
| if (requestPath.startsWith(path)) { | |||
| filterChain.doFilter(request, response); | |||
| return; | |||
| } | |||
| @@ -229,6 +231,7 @@ public class AuthzFilter extends GenericFilterBean { | |||
| /** | |||
| * Get user by login | |||
| * | |||
| * @return | |||
| */ | |||
| private Optional<UserDTO> getUserByLogin() { | |||
| @@ -247,6 +250,7 @@ public class AuthzFilter extends GenericFilterBean { | |||
| /** | |||
| * Get permission | |||
| * | |||
| * @param requestPath | |||
| * @param requestMethod | |||
| * @param requestType | |||
| @@ -259,14 +263,14 @@ public class AuthzFilter extends GenericFilterBean { | |||
| logger.info("Request Path: " + requestPath); | |||
| logger.info("Request Method: " + requestMethod); | |||
| logger.info("Request Type: " + requestType); | |||
| boolean result = enforcer.enforce(roleId.toString(), requestPath, requestMethod, requestType, "true"); | |||
| boolean result = enforcer.enforce(roleId.toString(), requestPath, requestMethod, requestType, "true"); | |||
| logger.info("Test is Permission Role of current user: " + result); | |||
| return result; | |||
| } | |||
| private boolean apiKeyHasPermission(HttpServletRequest request) | |||
| throws NoSuchAlgorithmException, InvalidKeyException { | |||
| String apiKeyToken = request.getHeader(AUTHORIZATION_API_KEY); | |||
| if (StringUtils.hasText(apiKeyToken)){ | |||
| if (StringUtils.hasText(apiKeyToken)) { | |||
| String timestamp = request.getHeader(TIMESTAMP_API_KEY); | |||
| Long customer_id = Long.parseLong(request.getHeader(CUSID_API_KEY)); | |||
| return apiKeyProvider.validateToken(customer_id, timestamp, apiKeyToken); | |||
| @@ -1,29 +1,29 @@ | |||
| package vn.azteam.tpf.service.mapper; | |||
| import org.mapstruct.Mapper; | |||
| import org.mapstruct.Mapping; | |||
| import vn.azteam.tpf.domain.TBCode; | |||
| import vn.azteam.tpf.domain.TBProductLabel; | |||
| import vn.azteam.tpf.service.dto.TBProductLabelDTO; | |||
| @Mapper(componentModel = "spring", uses = {TBDetailUserMapper.class}) | |||
| public interface TBProductLabelMapper extends EntityMapper<TBProductLabelDTO, TBProductLabel> { | |||
| @Mapping(source = "createdBy.id", target = "createdById") | |||
| @Mapping(source = "modifiedBy.id", target = "modifiedById") | |||
| @Mapping(source = "deletedBy.id", target = "deletedById") | |||
| TBProductLabelDTO toDto(TBProductLabel tbProductLabel); | |||
| @Mapping(source = "createdById", target = "createdBy") | |||
| @Mapping(source = "modifiedById", target = "modifiedBy") | |||
| @Mapping(source = "deletedById", target = "deletedBy") | |||
| TBProductLabel toEntity(TBProductLabelDTO tBProductLabelDTO); | |||
| default TBCode fromId(Long id) { | |||
| if (id == null) { | |||
| return null; | |||
| } | |||
| TBCode tBCode = new TBCode(); | |||
| tBCode.setId(id); | |||
| return tBCode; | |||
| } | |||
| } | |||
| //package vn.azteam.tpf.service.mapper; | |||
| // | |||
| //import org.mapstruct.Mapper; | |||
| //import org.mapstruct.Mapping; | |||
| //import vn.azteam.tpf.domain.TBCode; | |||
| //import vn.azteam.tpf.domain.TBProductLabel; | |||
| //import vn.azteam.tpf.service.dto.TBProductLabelDTO; | |||
| // | |||
| //@Mapper(componentModel = "spring", uses = {TBDetailUserMapper.class}) | |||
| //public interface TBProductLabelMapper extends EntityMapper<TBProductLabelDTO, TBProductLabel> { | |||
| // @Mapping(source = "createdBy.id", target = "createdById") | |||
| // @Mapping(source = "modifiedBy.id", target = "modifiedById") | |||
| // @Mapping(source = "deletedBy.id", target = "deletedById") | |||
| // TBProductLabelDTO toDto(TBProductLabel tbProductLabel); | |||
| // | |||
| // @Mapping(source = "createdById", target = "createdBy") | |||
| // @Mapping(source = "modifiedById", target = "modifiedBy") | |||
| // @Mapping(source = "deletedById", target = "deletedBy") | |||
| // TBProductLabel toEntity(TBProductLabelDTO tBProductLabelDTO); | |||
| // | |||
| // default TBCode fromId(Long id) { | |||
| // if (id == null) { | |||
| // return null; | |||
| // } | |||
| // TBCode tBCode = new TBCode(); | |||
| // tBCode.setId(id); | |||
| // return tBCode; | |||
| // } | |||
| //} | |||
| @@ -1,51 +1,51 @@ | |||
| package vn.azteam.tpf.web.rest; | |||
| import com.codahale.metrics.annotation.Timed; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.data.domain.Page; | |||
| import org.springframework.data.domain.Pageable; | |||
| import org.springframework.http.ResponseEntity; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import vn.azteam.tpf.service.TBProductLabelQueryService; | |||
| import vn.azteam.tpf.service.dto.TBProductLabelCriteria; | |||
| import vn.azteam.tpf.service.dto.TBProductLabelDTO; | |||
| import java.util.Comparator; | |||
| import java.util.List; | |||
| import java.util.stream.Collectors; | |||
| //@RestController | |||
| //@RequestMapping("/api") | |||
| public class TBProductLabelResource { | |||
| private static final String ENTITY_NAME = "tBProductLabel"; | |||
| private final TBProductLabelQueryService tBProductLabelQueryService; | |||
| public TBProductLabelResource(TBProductLabelQueryService tBProductLabelQueryService) { | |||
| this.tBProductLabelQueryService = tBProductLabelQueryService; | |||
| } | |||
| private final Logger log = LoggerFactory.getLogger(TBProductLabelResource.class); | |||
| @GetMapping("/tb-product-label/dropdown-list") | |||
| @Timed | |||
| public ResponseEntity<List<TBProductLabelDTO>> getAllTBProductLabelForDropdown(TBProductLabelCriteria criteria) { | |||
| log.debug("REST request to get TBCodes by criteria: {}", criteria); | |||
| Page<TBProductLabelDTO> page = tBProductLabelQueryService.findByCriteria(criteria, Pageable.unpaged()); | |||
| //Authorize get list crop by customer of current user | |||
| List<TBProductLabelDTO> result = page.getContent().stream() | |||
| .sorted(Comparator.comparing( | |||
| TBProductLabelDTO::getCreatedDate, | |||
| Comparator.nullsFirst(Comparator.naturalOrder())).reversed()) | |||
| .collect(Collectors.toList()); | |||
| return ResponseEntity.ok().headers(null).body(result); | |||
| } | |||
| } | |||
| //package vn.azteam.tpf.web.rest; | |||
| // | |||
| //import com.codahale.metrics.annotation.Timed; | |||
| //import org.slf4j.Logger; | |||
| //import org.slf4j.LoggerFactory; | |||
| //import org.springframework.data.domain.Page; | |||
| //import org.springframework.data.domain.Pageable; | |||
| //import org.springframework.http.ResponseEntity; | |||
| //import org.springframework.web.bind.annotation.GetMapping; | |||
| //import org.springframework.web.bind.annotation.RequestMapping; | |||
| //import org.springframework.web.bind.annotation.RestController; | |||
| //import vn.azteam.tpf.service.TBProductLabelQueryService; | |||
| //import vn.azteam.tpf.service.dto.TBProductLabelCriteria; | |||
| //import vn.azteam.tpf.service.dto.TBProductLabelDTO; | |||
| // | |||
| //import java.util.Comparator; | |||
| //import java.util.List; | |||
| //import java.util.stream.Collectors; | |||
| // | |||
| ////@RestController | |||
| ////@RequestMapping("/api") | |||
| //public class TBProductLabelResource { | |||
| // | |||
| // | |||
| // private static final String ENTITY_NAME = "tBProductLabel"; | |||
| // | |||
| // private final TBProductLabelQueryService tBProductLabelQueryService; | |||
| // | |||
| // public TBProductLabelResource(TBProductLabelQueryService tBProductLabelQueryService) { | |||
| // this.tBProductLabelQueryService = tBProductLabelQueryService; | |||
| // } | |||
| // | |||
| // private final Logger log = LoggerFactory.getLogger(TBProductLabelResource.class); | |||
| // | |||
| // @GetMapping("/tb-product-label/dropdown-list") | |||
| // @Timed | |||
| // public ResponseEntity<List<TBProductLabelDTO>> getAllTBProductLabelForDropdown(TBProductLabelCriteria criteria) { | |||
| // log.debug("REST request to get TBCodes by criteria: {}", criteria); | |||
| // Page<TBProductLabelDTO> page = tBProductLabelQueryService.findByCriteria(criteria, Pageable.unpaged()); | |||
| // | |||
| // //Authorize get list crop by customer of current user | |||
| // List<TBProductLabelDTO> result = page.getContent().stream() | |||
| // .sorted(Comparator.comparing( | |||
| // TBProductLabelDTO::getCreatedDate, | |||
| // Comparator.nullsFirst(Comparator.naturalOrder())).reversed()) | |||
| // .collect(Collectors.toList()); | |||
| // | |||
| // return ResponseEntity.ok().headers(null).body(result); | |||
| // } | |||
| // | |||
| //} | |||
| @@ -1,18 +1,18 @@ | |||
| CREATE TABLE tb_product_label | |||
| ( | |||
| id bigint not null auto_increment, | |||
| media varchar(255), | |||
| description varchar(255), | |||
| created_date timestamp, | |||
| modified_date timestamp, | |||
| deleted_date timestamp, | |||
| created_by bigint, | |||
| modified_by bigint, | |||
| deleted_by bigint, | |||
| PRIMARY KEY (id) | |||
| ); | |||
| ALTER TABLE tb_code | |||
| ADD tb_product_label_id bigint; | |||
| -- CREATE TABLE tb_product_label | |||
| -- ( | |||
| -- id bigint not null auto_increment, | |||
| -- media varchar(255), | |||
| -- description varchar(255), | |||
| -- created_date timestamp, | |||
| -- modified_date timestamp, | |||
| -- deleted_date timestamp, | |||
| -- created_by bigint, | |||
| -- modified_by bigint, | |||
| -- deleted_by bigint, | |||
| -- PRIMARY KEY (id) | |||
| -- ); | |||
| -- | |||
| -- ALTER TABLE tb_code | |||
| -- ADD tb_product_label_id bigint; | |||
| -- | |||
| -- | |||