use of org.broadinstitute.consent.http.models.Dac in project consent by DataBiosphere.
the class DacWithDatasetsReducer method accumulate.
@Override
public void accumulate(Map<Integer, Dac> container, RowView rowView) {
try {
Dac dac = container.computeIfAbsent(rowView.getColumn("dac_id", Integer.class), id -> rowView.getRow(Dac.class));
if (Objects.nonNull(rowView.getColumn("datasetid", Integer.class))) {
DatasetDTO dto = rowView.getRow(DatasetDTO.class);
try {
if (Objects.nonNull(rowView.getColumn("dataset_alias", String.class))) {
String dsAlias = rowView.getColumn("dataset_alias", String.class);
try {
dto.setAlias(Integer.parseInt(dsAlias));
} catch (Exception e) {
logger.error("Exception parsing dataset alias: " + dsAlias, e);
}
}
if (Objects.nonNull(rowView.getColumn("dataset_create_date", Date.class))) {
Date createDate = rowView.getColumn("dataset_create_date", Date.class);
dto.setCreateDate(createDate);
}
if (Objects.nonNull(rowView.getColumn("dataset_update_date", Timestamp.class))) {
Timestamp updateDate = rowView.getColumn("dataset_update_date", Timestamp.class);
dto.setUpdateDate(updateDate);
}
} catch (Exception e) {
// no values for these columns
}
if (Objects.nonNull(rowView.getColumn("consent_data_use", String.class))) {
String duStr = rowView.getColumn("consent_data_use", String.class);
Optional<DataUse> du = DataUse.parseDataUse(duStr);
du.ifPresent(dto::setDataUse);
}
if (Objects.nonNull(dto)) {
dac.addDatasetDTO(dto);
}
}
} catch (MappingException e) {
logger.warn(e.getMessage());
}
}
use of org.broadinstitute.consent.http.models.Dac in project consent by DataBiosphere.
the class MetricsServiceTest method generateDac.
private Dac generateDac() {
Dac dac = new Dac();
dac.setDacId(1);
dac.setDescription("description");
dac.setName("dac1");
User chairUser = new User();
chairUser.setDacUserId(1);
chairUser.setEmail("chair@test.org");
chairUser.setDisplayName("Chair");
UserRole chairRole = new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
chairUser.setRoles(Collections.singletonList(chairRole));
User memberUser = new User();
memberUser.setDacUserId(2);
memberUser.setEmail("member@test.org");
memberUser.setDisplayName("Member");
UserRole memberRole = new UserRole(UserRoles.MEMBER.getRoleId(), UserRoles.MEMBER.getRoleName());
memberUser.setRoles(Collections.singletonList(memberRole));
dac.setChairpersons(Collections.singletonList(chairUser));
dac.setMembers(Collections.singletonList(memberUser));
return dac;
}
use of org.broadinstitute.consent.http.models.Dac in project consent by DataBiosphere.
the class DacResourceTest method testFindById_success.
@Test
public void testFindById_success() {
Dac dac = new DacBuilder().setDacId(1).setName("name").setDescription("description").build();
when(dacService.findById(1)).thenReturn(dac);
Response response = dacResource.findById(dac.getDacId());
assertEquals(200, response.getStatus());
}
use of org.broadinstitute.consent.http.models.Dac in project consent by DataBiosphere.
the class DacResourceTest method testRemoveDacChairAsAdmin.
@Test
public void testRemoveDacChairAsAdmin() {
Dac dac = buildDac(null);
when(dacService.findById(any())).thenReturn(dac);
User admin = buildAdmin(authUser);
User member = buildUser();
when(userService.findUserByEmail(authUser.getEmail())).thenReturn(admin);
when(dacService.findUserById(member.getDacUserId())).thenReturn(member);
Response response = dacResource.removeDacChair(authUser, dac.getDacId(), member.getDacUserId());
assertEquals(HttpStatusCodes.STATUS_CODE_OK, response.getStatus());
}
use of org.broadinstitute.consent.http.models.Dac in project consent by DataBiosphere.
the class ConsentElectionResource method createConsentElectionForDac.
@POST
@Consumes("application/json")
@Path("/dac/{dacId}")
@RolesAllowed({ ADMIN, CHAIRPERSON })
public Response createConsentElectionForDac(@Auth AuthUser authUser, @Context UriInfo info, @PathParam("consentId") String consentId, @PathParam("dacId") Integer dacId, Election election) {
URI uri;
try {
Consent consent = consentService.getById(consentId);
Dac dac = dacService.findById(dacId);
if (dac == null) {
throw new NotFoundException("Cannot find DAC with the provided id: " + dacId);
}
if (consent.getDacId() != null && !consent.getDacId().equals(dacId)) {
throw new BadRequestException("Consent is already associated to a DAC.");
}
try {
consentService.updateConsentDac(consentId, dacId);
} catch (Exception e) {
logger().error("Exception updating consent id: '" + consentId + "', with dac id: '" + dacId + "'");
throw new InternalServerErrorException("Unable to associate consent to dac.");
}
uri = createElectionURI(info, election, consentId);
} catch (Exception e) {
return createExceptionResponse(e);
}
return Response.created(uri).build();
}
Aggregations