Skip to content

Commit

Permalink
Merge branch 'develop' into participant-manager-issue-960
Browse files Browse the repository at this point in the history
  • Loading branch information
Kantharajut-btc authored Sep 21, 2020
2 parents a65e77a + 6c07bda commit e02c206
Show file tree
Hide file tree
Showing 213 changed files with 2,864 additions and 5,809 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
@ToString
public class AuditLogEventRequest implements Serializable {

private static final long serialVersionUID = -2284303463534623314L;

@NotBlank
@Size(max = 36)
private String correlationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,20 @@ private CommonConstants() {}

public static final int EMAIL_LENGTH = 320;

public static final String DELETE = "delete";
public static final String SUPER_ADMIN = "Super Admin";

public static final String RETAIN = "retain";
public static final String ADMIN = "Admin";

public static final String EDITED_USER_ID = "edited_user_id";

public static final String NEW_USER_ID = "new_user_id";

public static final double DEFAULT_PERCENTAGE = 100.00;

public static final String DELETE = "delete";

public static final String RETAIN = "retain";

public static final String NO_OF_RECORDS = "5";

public static final String PAGE_NO = "0";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/

package com.google.cloud.healthcare.fdamystudies.common;

public enum DataSharingStatus {
UNDEFINED("Undefined"),
NOT_APPLICABLE("Not Applicable"),
NOT_PERMITTED("Not Permitted"),
PERMITTED("Permitted");

private String value;

private DataSharingStatus(String value) {
this.value = value;
}

public String value() {
return value;
}

public static DataSharingStatus fromValue(String value) {
for (DataSharingStatus e : DataSharingStatus.values()) {
if (e.value.equals(value)) {
return e;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,15 @@ public enum ErrorCode {
CANNOT_ADD_SITE_FOR_OPEN_STUDY(
403, "EC_0053", HttpStatus.FORBIDDEN.toString(), "Cannot add site to open study"),

USER_ID_REQUIRED(400, "EC_0054", Constants.BAD_REQUEST, "User Id is required");
USER_ID_REQUIRED(400, "EC_0054", Constants.BAD_REQUEST, "User Id is required"),

EMAIL_ID_OR_PASSWORD_NULL(
400, "EC_0055", Constants.BAD_REQUEST, "emailId or password is blank in request"),

APPLICATION_ID_MISSING(
400, "EC_0056", Constants.BAD_REQUEST, "applicationId is missing in request header"),

INVALID_DATA_SHARING_STATUS(400, "EC-120", Constants.BAD_REQUEST, "Invalid data sharing status.");

private final int status;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
Expand All @@ -31,7 +31,7 @@ public class CommonModuleConfiguration implements WebMvcConfigurer {

@Value("${cors.allowed.origins:}")
private String corsAllowedOrigins;

@Autowired
private RestTemplateAuthTokenModifierInterceptor restTemplateAuthTokenModifierInterceptor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DataSource dataSource() {
return dataSource;
}

@Bean
@Bean(name = "entityManagerFactory")
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ErrorResponse handleRestClientResponseException(
}

@ExceptionHandler(ErrorCodeException.class)
public ResponseEntity<ErrorCode> handleHttpMessageNotReadableException(ErrorCodeException e) {
public ResponseEntity<ErrorCode> handleErrorCodeException(ErrorCodeException e) {
logger.error("request failed with ErrorCode", e);
return ResponseEntity.status(e.getErrorCode().getStatus()).body(e.getErrorCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static AuditLogEventRequest fromHttpServletRequest(HttpServletRequest req
auditRequest.setUserId(getValue(request, USER_ID));
auditRequest.setSource(getValue(request, SOURCE));
auditRequest.setUserIp(getUserIP(request));
auditRequest.setSource(getValue(request, SOURCE));

MobilePlatform mobilePlatform = MobilePlatform.fromValue(getValue(request, MOBILE_PLATFORM));
auditRequest.setMobilePlatform(mobilePlatform.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

@Setter
@Getter
Expand Down Expand Up @@ -85,8 +84,8 @@ public class ParticipantStudyEntity implements Serializable {
@CreationTimestamp
private Timestamp enrolledDate;

@Type(type = "java.lang.Boolean")
private Boolean sharing;
@Column(name = "data_sharing_status", length = SMALL_LENGTH)
private String sharing;

private Integer completion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -40,6 +43,9 @@

@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(
name = "study_info",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.CreationTimestamp;
Expand All @@ -39,7 +42,10 @@
@Setter
@Getter
@ToString
@Builder
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(
name = "user_details",
uniqueConstraints = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/

package com.google.cloud.healthcare.fdamystudies.repository;

import com.google.cloud.healthcare.fdamystudies.model.AppEntity;
import java.util.Optional;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
@ConditionalOnProperty(
value = "participant.manager.repository.enabled",
havingValue = "true",
matchIfMissing = false)
public interface AppRepository extends JpaRepository<AppEntity, String> {}
public interface AppRepository extends JpaRepository<AppEntity, String> {

@Query("SELECT app from AppEntity app where app.appId=:appId")
public Optional<AppEntity> findByAppId(String appId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/

package com.google.cloud.healthcare.fdamystudies.repository;

import com.google.cloud.healthcare.fdamystudies.model.AuthInfoEntity;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
@ConditionalOnProperty(
value = "participant.manager.repository.enabled",
havingValue = "true",
matchIfMissing = false)
public interface AuthInfoRepository extends JpaRepository<AuthInfoEntity, String> {

@Query(
"SELECT a FROM UserAppDetailsEntity u,AuthInfoEntity a where u.userDetails = a.userDetails and u.app.id in (?1) and a.remoteNotificationFlag=1 and "
+ "(a.deviceToken is not NULL and a.deviceToken != '' and a.deviceType is not NULL and a.deviceType != '') ")
public List<AuthInfoEntity> findDevicesTokens(List<String> appInfoIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.google.cloud.healthcare.fdamystudies.model.StudyConsentEntity;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
Expand All @@ -24,5 +26,10 @@ public interface StudyConsentRepository extends JpaRepository<StudyConsentEntity

@Query(
"SELECT sc FROM StudyConsentEntity sc WHERE sc.participantStudy.id in (:participantStudyIds)")
public List<StudyConsentEntity> findByParticipantRegistrySiteId(List<String> participantStudyIds);
public Page<StudyConsentEntity> findByParticipantRegistrySiteId(
List<String> participantStudyIds, Pageable page);

@Query(
"SELECT COUNT(sc) FROM StudyConsentEntity sc WHERE sc.participantStudy.id in (:participantStudyIds)")
public Long countByParticipantRegistrySiteId(List<String> participantStudyIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@

package com.google.cloud.healthcare.fdamystudies.repository;

import com.google.cloud.healthcare.fdamystudies.usermgmt.model.UserAppDetailsBO;
import com.google.cloud.healthcare.fdamystudies.model.UserAppDetailsEntity;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserAppDetailsRepository extends JpaRepository<UserAppDetailsBO, Integer> {}
@ConditionalOnProperty(
value = "participant.manager.repository.enabled",
havingValue = "true",
matchIfMissing = false)
public interface UserAppDetailsRepository extends JpaRepository<UserAppDetailsEntity, String> {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.google.cloud.healthcare.fdamystudies.model.AppCount;
import com.google.cloud.healthcare.fdamystudies.model.UserDetailsEntity;
import java.util.List;
import java.util.Optional;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -30,4 +31,16 @@ public interface UserDetailsRepository extends JpaRepository<UserDetailsEntity,

@Query("SELECT ud FROM UserDetailsEntity ud WHERE ud.app.id = :appInfoId")
public List<UserDetailsEntity> findByAppId(String appInfoId);

<T> List<T> findByUserId(String userId, Class<T> d);

List<UserDetailsEntity> findByEmail(String emailId);

@Query("SELECT ud FROM UserDetailsEntity ud WHERE ud.email = :email and ud.app.appId = :appId")
Optional<UserDetailsEntity> findByEmailAndAppId(String email, String appId);

public List<UserDetailsEntity> findByLastName(String lastname);

@Query("SELECT ud FROM UserDetailsEntity ud WHERE ud.userId = :userId")
public Optional<UserDetailsEntity> findByUserId(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@

package com.google.cloud.healthcare.fdamystudies.repository;

import com.google.cloud.healthcare.fdamystudies.usermgmt.model.UserInstitution;
import com.google.cloud.healthcare.fdamystudies.model.UserInstitutionEntity;
import java.util.Optional;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@ConditionalOnProperty(
value = "participant.manager.repository.enabled",
havingValue = "true",
matchIfMissing = false)
@Transactional
public interface UserInstitutionRepository extends JpaRepository<UserInstitution, Long> {
Optional<UserInstitution> findByUserUserId(String userId);
public interface UserInstitutionRepository extends JpaRepository<UserInstitutionEntity, String> {

@Query("SELECT ud FROM UserInstitutionEntity ud WHERE ud.id = :userId")
Optional<UserInstitutionEntity> findByUserUserId(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,33 @@ protected void clearAuditRequests() {
auditRequests.clear();
}

protected MimeMessage verifyMimeMessage(
String toEmail, String fromEmail, String subject, String body)
throws MessagingException, IOException {
ArgumentCaptor<MimeMessage> mailCaptor = ArgumentCaptor.forClass(MimeMessage.class);
verify(emailSender, atLeastOnce()).send(mailCaptor.capture());

MimeMessage mail = mailCaptor.getValue();

assertThat(mail.getFrom()).containsExactly(new InternetAddress(fromEmail));
assertThat(mail.getRecipients(Message.RecipientType.TO))
.containsExactly(new InternetAddress(toEmail));
assertThat(mail.getRecipients(Message.RecipientType.CC)).isNull();

assertThat(mail.getSubject()).isEqualTo(subject);
assertThat(mail.getContent().toString()).contains(body);

assertThat(mail.getDataHandler().getContentType()).isEqualTo("text/html; charset=utf-8");

return mail;
}

protected void verifyDoesNotContain(String text, String... searchValues) {
for (String value : searchValues) {
assertFalse(StringUtils.contains(text, value));
}
}

@BeforeEach
void setUp(TestInfo testInfo) {
logger.entry(String.format("TEST STARTED: %s", testInfo.getDisplayName()));
Expand Down Expand Up @@ -299,22 +326,4 @@ protected void verifyTokenIntrospectRequest(int times) {
postRequestedFor(urlEqualTo("/oauth-scim-service/oauth2/introspect"))
.withRequestBody(new ContainsPattern(VALID_TOKEN)));
}

protected void verifyMimeMessage(String toEmail, String fromEmail, String subject, String body)
throws MessagingException, IOException {
ArgumentCaptor<MimeMessage> mailCaptor = ArgumentCaptor.forClass(MimeMessage.class);
verify(emailSender, atLeastOnce()).send(mailCaptor.capture());

MimeMessage mail = mailCaptor.getValue();

assertThat(mail.getFrom()).containsExactly(new InternetAddress(fromEmail));
assertThat(mail.getRecipients(Message.RecipientType.TO))
.containsExactly(new InternetAddress(toEmail));
assertThat(mail.getRecipients(Message.RecipientType.CC)).isNull();

assertThat(mail.getSubject()).isEqualTo(subject);
assertThat(mail.getContent().toString()).contains(body);

assertThat(mail.getDataHandler().getContentType()).isEqualTo("text/html; charset=utf-8");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"code": "200",
"message": "SUCCESS",
"isValidClient": true
}
Loading

0 comments on commit e02c206

Please sign in to comment.