use of org.sagebionetworks.bridge.BridgeUtils.StudyAssociations in project BridgeServer2 by Sage-Bionetworks.
the class HibernateAccountDao method unmarshallAccountSummary.
// Helper method to unmarshall a HibernateAccount into an AccountSummary.
// Package-scoped to facilitate unit tests.
AccountSummary unmarshallAccountSummary(HibernateAccount acct) {
AccountSummary.Builder builder = new AccountSummary.Builder();
builder.withAppId(acct.getAppId());
builder.withId(acct.getId());
builder.withFirstName(acct.getFirstName());
builder.withLastName(acct.getLastName());
builder.withEmail(acct.getEmail());
builder.withPhone(acct.getPhone());
builder.withCreatedOn(acct.getCreatedOn());
builder.withStatus(acct.getStatus());
builder.withSynapseUserId(acct.getSynapseUserId());
builder.withAttributes(acct.getAttributes());
builder.withOrgMembership(acct.getOrgMembership());
builder.withNote(acct.getNote());
builder.withClientTimeZone(acct.getClientTimeZone());
builder.withRoles(acct.getRoles());
builder.withDataGroups(acct.getDataGroups());
StudyAssociations assoc = BridgeUtils.studyAssociationsVisibleToCaller(null);
if (acct.getId() != null) {
assoc = BridgeUtils.studyAssociationsVisibleToCaller(acct);
}
builder.withExternalIds(assoc.getExternalIdsVisibleToCaller());
builder.withStudyIds(assoc.getStudyIdsVisibleToCaller());
return builder.build();
}
use of org.sagebionetworks.bridge.BridgeUtils.StudyAssociations in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantService method getSelfParticipant.
public StudyParticipant getSelfParticipant(App app, CriteriaContext context, boolean includeHistory) {
AccountId accountId = AccountId.forId(app.getIdentifier(), context.getUserId());
// already filters for study
Account account = getAccountThrowingException(accountId);
StudyParticipant.Builder builder = new StudyParticipant.Builder();
StudyAssociations assoc = studyAssociationsVisibleToCaller(account);
copyAccountToParticipant(builder, assoc, account);
copyConsentStatusToParticipant(builder, account, context);
if (includeHistory) {
copyHistoryToParticipant(builder, account, context.getAppId());
}
return builder.build();
}
use of org.sagebionetworks.bridge.BridgeUtils.StudyAssociations in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantService method getParticipant.
public StudyParticipant getParticipant(App app, Account account, boolean includeHistory) {
if (account == null) {
// This should never happen. However, it occasionally does happen, generally only during integration tests.
// If a call is taking a long time for whatever reason, the call will timeout and the tests will delete the
// account. If this happens in the middle of a call (such as give consent or update self participant),
// we'll suddenly have no account here.
//
// We'll still want to log an error for this so we'll be aware when it happens. At the very least, we'll
// have this comment and a marginally useful error message instead of a mysterious null pointer exception.
//
// See https://sagebionetworks.jira.com/browse/BRIDGE-1463 for more info.
LOG.error("getParticipant() called with no account. Was the account deleted in the middle of the call?");
throw new EntityNotFoundException(Account.class);
}
StudyParticipant.Builder builder = new StudyParticipant.Builder();
StudyAssociations assoc = studyAssociationsVisibleToCaller(account);
copyAccountToParticipant(builder, assoc, account);
if (includeHistory) {
copyHistoryToParticipant(builder, account, app.getIdentifier());
}
// Without requestInfo, we cannot reliably determine if the user is consented
RequestInfo requestInfo = requestInfoService.getRequestInfo(account.getId());
if (requestInfo != null) {
CriteriaContext context = new CriteriaContext.Builder().withAppId(app.getIdentifier()).withUserId(account.getId()).withHealthCode(account.getHealthCode()).withUserDataGroups(account.getDataGroups()).withUserStudyIds(assoc.getStudyIdsVisibleToCaller()).withClientInfo(requestInfo.getClientInfo()).withLanguages(requestInfo.getLanguages()).build();
copyConsentStatusToParticipant(builder, account, context);
}
return builder.build();
}
Aggregations