Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
Expand All @@ -71,8 +72,8 @@
import javax.validation.Valid;
import java.io.IOException;
import java.security.Principal;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;

import static com.odysseusinc.athena.util.CDMVersion.getByValue;
import static com.odysseusinc.athena.util.CDMVersion.notExist;
Expand All @@ -93,9 +94,10 @@ public class VocabularyController {
private final VocabularyService vocabularyService;
private final LicenseService licenseService;
private final VocabularyServiceV5 vocabularyServiceV5;
private final GenericConversionService conversionService;

@Autowired
public VocabularyController(ConverterUtils converterUtils, DownloadBundleService downloadBundleService, DownloadShareService downloadShareService, LicenseService licenseService, UserService userService, VocabularyConversionService vocabularyConversionService, VocabularyService vocabularyService, VocabularyServiceV5 vocabularyServiceV5) {
public VocabularyController(ConverterUtils converterUtils, DownloadBundleService downloadBundleService, DownloadShareService downloadShareService, LicenseService licenseService, UserService userService, VocabularyConversionService vocabularyConversionService, VocabularyService vocabularyService, VocabularyServiceV5 vocabularyServiceV5, GenericConversionService conversionService) {
this.converterUtils = converterUtils;
this.downloadBundleService = downloadBundleService;
this.downloadShareService = downloadShareService;
Expand All @@ -104,6 +106,7 @@ public VocabularyController(ConverterUtils converterUtils, DownloadBundleService
this.vocabularyService = vocabularyService;
this.licenseService = licenseService;
this.vocabularyServiceV5 = vocabularyServiceV5;
this.conversionService = conversionService;
}

@Operation(summary = "Get vocabularies.")
Expand Down Expand Up @@ -200,6 +203,17 @@ public Page<UserLicensesDTO> getLicenses(
final Page<AthenaUser> users = userService.getUsersWithLicenses(pageRequest, query, pendingOnly);

List<UserLicensesDTO> dtos = converterUtils.convertList(users.getContent(), UserLicensesDTO.class);
users.getContent().forEach(athenaUser -> {
athenaUser.getLicenses().forEach(license -> {
dtos.forEach(userLicensesDTO -> {
userLicensesDTO.getVocabularyDTOs().forEach(a -> {
if (a.getId() == license.getId().intValue()) a.setExpiredDate(license.getExpiredDate());
});
});
});

});

return new CustomPageImpl(dtos, pageRequest, users.getTotalElements());
}

Expand All @@ -218,7 +232,7 @@ public List<VocabularyDTO> suggestLicenses(@RequestParam("userId") Long userId)
public ResponseEntity<Void> saveLicenses(@RequestBody @Valid AddingUserLicensesDTO dto) {

final AthenaUser user = userService.get(dto.getUserId());
vocabularyService.grantLicenses(user, dto.getVocabularyV4Ids());
vocabularyService.grantLicenses(user, dto.getVocabularyV4Ids(), dto.getExpiredDate());
return ResponseEntity.ok().build();
}

Expand All @@ -235,7 +249,15 @@ public ResponseEntity<Void> removeLicenses(@PathVariable("id") Long licenseId) {
@PostMapping("licenses/request")
public ResponseEntity<Void> requestLicense(Principal principal, @Valid @RequestBody LicenseRequestDTO dto) {

licenseService.requestLicense(principal, dto.getVocabularyId());
Date expiredDate;
if(dto.getExpiredDate() == null){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 2);
expiredDate = cal.getTime();
}else{
expiredDate = dto.getExpiredDate();
}
licenseService.requestLicense(principal, dto.getVocabularyId(), expiredDate);
return ResponseEntity.ok().build();
}

Expand All @@ -245,7 +267,7 @@ public ResponseEntity<Void> requestLicense(Principal principal, @Valid @RequestB
public ResponseEntity<Void> acceptLicense(@Valid @RequestBody AcceptDTO acceptDTO) {

licenseService.checkLicense(acceptDTO.getId());
vocabularyService.acceptLicense(acceptDTO.getId(), acceptDTO.getAccepted());
vocabularyService.acceptLicense(acceptDTO.getId(), acceptDTO.getAccepted(), acceptDTO.getExpiredDate());
return ResponseEntity.ok().build();
}

Expand All @@ -254,10 +276,11 @@ public ResponseEntity<Void> acceptLicense(@Valid @RequestBody AcceptDTO acceptDT
public void acceptLicenseViaMail(@RequestParam("id") Long id,
@RequestParam("accepted") Boolean accepted,
@RequestParam("token") String token,
@RequestParam("expiredDate") Date expiredDate,
HttpServletResponse response) throws IOException {

licenseService.checkLicense(id, token);
vocabularyService.acceptLicense(id, accepted);
vocabularyService.acceptLicense(id, accepted, expiredDate);
response.sendRedirect("/admin/licenses");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void putIntoJsonFacet(JSONObject jsonFacet, String facetField) {
jsonFacet.put(getFacetLabel(facetField), new JSONObject()
.put("type", "terms")
.put("field", facetField)
.put("limit", -1)
.put("limit", 100)
.put("missing", true)
.put("mincount", 0)
.put("domain",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public List<UserVocabularyDTO> convert(@NotNull List<VocabularyDTO> vocabularyDT
License license = map.get(each.getId());
if (license != null) {
res.setStatus(license.getStatus());
res.setExpiredDate(license.getExpiredDate());
}
res.setAvailable(
isEmpty(each.getRequired()) || (availableIdV4s.contains(each.getId()) && each.getUrl() != null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
package com.odysseusinc.athena.api.v1.controller.dto.vocabulary;

import javax.validation.constraints.NotNull;
import java.util.Date;

public class AcceptDTO {
@NotNull
private Long id;
@NotNull
private Boolean accepted;

private Date expiredDate;

public Long getId() {

return id;
Expand All @@ -40,6 +43,16 @@ public void setId(Long id) {
this.id = id;
}

public Date getExpiredDate() {

return expiredDate;
}

public void setExpiredDate(Date expiredDate) {

this.expiredDate = expiredDate;
}

public Boolean getAccepted() {

return accepted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.odysseusinc.athena.api.v1.controller.dto.vocabulary;

import java.util.Date;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
Expand All @@ -35,6 +36,8 @@ public class AddingUserLicensesDTO {
@Size(min = 1)
private List<Integer> vocabularyV4Ids;

private Date expiredDate;

public Long getUserId() {

return userId;
Expand All @@ -54,4 +57,14 @@ public void setVocabularyV4Ids(List<Integer> vocabularyV4Ids) {

this.vocabularyV4Ids = vocabularyV4Ids;
}

public Date getExpiredDate() {

return expiredDate;
}

public void setVocabularyV4Ids(Date expiredDate) {

this.expiredDate = expiredDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.odysseusinc.athena.api.v1.controller.dto.vocabulary;

import javax.validation.constraints.NotNull;
import java.util.Date;

public class LicenseRequestDTO {
@NotNull
Expand All @@ -37,4 +38,16 @@ public void setVocabularyId(Integer vocabularyId) {

this.vocabularyId = vocabularyId;
}

private Date expiredDate;

public Date getExpiredDate() {

return expiredDate;
}

public void setExpiredDate(Date expiredDate) {

this.expiredDate = expiredDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class VocabularyDTO {
private boolean clickDefault;
private boolean omopReq;
private String url;
private Date expiredDate;
private String statusLicense;

public VocabularyDTO() {

Expand All @@ -48,6 +50,8 @@ public VocabularyDTO(VocabularyDTO other) {
this.clickDefault = other.clickDefault;
this.omopReq = other.omopReq;
this.url = other.url;
this.expiredDate = other.expiredDate;
this.statusLicense = other.statusLicense;
}

public static VocabularyDTO.VocabularyDTOBuilder builder() {
Expand Down Expand Up @@ -135,6 +139,25 @@ public void setUrl(String url) {
this.url = url;
}

public Date getExpiredDate() {

return expiredDate;
}

public void setExpiredDate(Date expiredDate) {

this.expiredDate = expiredDate;
}
public String getStatusLicense() {

return statusLicense;
}

public void setStatusLicense(String statusLicense) {

this.statusLicense = statusLicense;
}

public class VocabularyDTOBuilder {
private Integer id;
private String code;
Expand All @@ -144,6 +167,9 @@ public class VocabularyDTOBuilder {
private boolean clickDefault;
private boolean omopReq;
private String url;
private Date expiredDate;
private String statusLicense;


private VocabularyDTOBuilder() {

Expand Down Expand Up @@ -207,6 +233,18 @@ public VocabularyDTOBuilder setUrl(String url) {
return this;
}

public VocabularyDTOBuilder setExpiredDate(Date expiredDate) {

VocabularyDTO.this.expiredDate = expiredDate;
return this;
}

public VocabularyDTOBuilder setStatusLicense(String statusLicense) {

VocabularyDTO.this.statusLicense = statusLicense;
return this;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,10 @@ public Executor emailsExecutor() {

return Executors.newSingleThreadExecutor();
}

@Bean(name = "emailSenderExecutor")
public Executor checkDownloadHistory() {

return Executors.newSingleThreadExecutor();
}
}
16 changes: 15 additions & 1 deletion src/main/java/com/odysseusinc/athena/model/athena/License.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ public License() {

}

public License(AthenaUser user, VocabularyConversion vocabularyConversion, LicenseStatus status) {
public License(AthenaUser user, VocabularyConversion vocabularyConversion, LicenseStatus status, Date expirationDate) {

this.user = user;
this.vocabularyConversion = vocabularyConversion;
this.status = status;
this.token = UUID.randomUUID().toString().replace("-", "");
this.expiredDate = expiredDate;
}

@Id
Expand Down Expand Up @@ -81,6 +82,9 @@ public License(AthenaUser user, VocabularyConversion vocabularyConversion, Licen
@Column(name = "request_date")
private Date requestDate;

@Column(name = "expired_date")
private Date expiredDate;

public Long getId() {

return id;
Expand Down Expand Up @@ -140,4 +144,14 @@ public void setRequestDate(Date requestDate) {

this.requestDate = requestDate;
}

public Date getExpiredDate() {

return expiredDate;
}

public void setExpiredDate(Date expiredDate) {

this.expiredDate = expiredDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public interface AthenaUserRepository extends PagingAndSortingRepository<AthenaUser, Long> {

String GET_USERS_WITH_LICENSES = " FROM users us WHERE "
+ "id IN (SELECT DISTINCT user_id FROM licenses where status IN ('PENDING') OR :pendingOnly IS FALSE) "
+ "id IN (SELECT DISTINCT user_id FROM licenses where status IN ('PENDING') OR :pendingOnly IS FALSE AND expired_date > CURRENT_DATE) "
+ "AND (lower(firstname) SIMILAR TO :suggestRequest "
+ "OR lower(lastname) SIMILAR TO :suggestRequest "
+ "OR lower(middlename) SIMILAR TO :suggestRequest) ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.odysseusinc.athena.api.v1.controller.dto.LicenseExceptionDTO;

import java.security.Principal;
import java.util.Date;

public interface LicenseService {

Expand All @@ -12,5 +13,5 @@ public interface LicenseService {

void checkLicense(Long id);

Long requestLicense(Principal principal, Integer vocabularyId);
Long requestLicense(Principal principal, Integer vocabularyId, Date expirationDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
import com.odysseusinc.athena.model.athena.Notification;
import com.odysseusinc.athena.model.security.AthenaUser;
import com.odysseusinc.athena.util.CDMVersion;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Service
public interface VocabularyService {

List<UserVocabularyDTO> getAllForCurrentUser();
Expand All @@ -52,13 +56,13 @@ public interface VocabularyService {

void checkBundleAndSharedUser(AthenaUser user, DownloadBundle bundle);

Iterable<License> grantLicenses(AthenaUser user, List<Integer> vocabularyV4Ids);
Iterable<License> grantLicenses(AthenaUser user, List<Integer> vocabularyV4Ids, Date expiredDate);

Long requestLicense(AthenaUser user, Integer vocabularyV4Id);
Long requestLicense(AthenaUser user, Integer vocabularyV4Id, Date expiredDate);

void deleteLicense(Long licenseId);

void acceptLicense(Long id, boolean accepted);
void acceptLicense(Long id, boolean accepted, Date expiredDate);

License get(AthenaUser user, Integer vocabularyId);

Expand Down
Loading