Search in sources :

Example 1 with Dictionary

use of org.broadinstitute.consent.http.models.Dictionary in project consent by DataBiosphere.

the class DatasetResource method downloadDataSets.

@POST
@Path("/download")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public Response downloadDataSets(List<Integer> idList) {
    try {
        String msg = "GETing DataSets to download";
        logger().debug(msg);
        JSONObject json = new JSONObject();
        Collection<Dictionary> headers = datasetService.describeDictionaryByReceiveOrder();
        StringBuilder sb = new StringBuilder();
        String TSV_DELIMITER = "\t";
        for (Dictionary header : headers) {
            if (sb.length() > 0)
                sb.append(TSV_DELIMITER);
            sb.append(header.getKey());
        }
        sb.append(END_OF_LINE);
        if (CollectionUtils.isEmpty(idList)) {
            json.put("datasets", sb.toString());
            return Response.ok(json.toString(), MediaType.APPLICATION_JSON).build();
        }
        Collection<DatasetDTO> rows = datasetService.describeDataSetsByReceiveOrder(idList);
        for (DatasetDTO row : rows) {
            StringBuilder sbr = new StringBuilder();
            DataSetPropertyDTO property = new DataSetPropertyDTO("Consent ID", row.getConsentId());
            List<DataSetPropertyDTO> props = row.getProperties();
            props.add(property);
            for (DataSetPropertyDTO prop : props) {
                if (sbr.length() > 0)
                    sbr.append(TSV_DELIMITER);
                sbr.append(prop.getPropertyValue());
            }
            sbr.append(END_OF_LINE);
            sb.append(sbr);
        }
        String tsv = sb.toString();
        json.put("datasets", tsv);
        return Response.ok(json.toString(), MediaType.APPLICATION_JSON).build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) Dictionary(org.broadinstitute.consent.http.models.Dictionary) JSONObject(org.json.JSONObject) DataSetPropertyDTO(org.broadinstitute.consent.http.models.dto.DataSetPropertyDTO) ClientErrorException(javax.ws.rs.ClientErrorException) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PermitAll(javax.annotation.security.PermitAll)

Example 2 with Dictionary

use of org.broadinstitute.consent.http.models.Dictionary in project consent by DataBiosphere.

the class DatasetService method processDatasetProperties.

public List<DataSetProperty> processDatasetProperties(Integer datasetId, List<DataSetPropertyDTO> properties) {
    Date now = new Date();
    List<Dictionary> dictionaries = datasetDAO.getMappedFieldsOrderByReceiveOrder();
    List<String> keys = dictionaries.stream().map(Dictionary::getKey).collect(Collectors.toList());
    return properties.stream().filter(p -> keys.contains(p.getPropertyName()) && !p.getPropertyName().equals(DATASET_NAME_KEY)).map(p -> new DataSetProperty(datasetId, dictionaries.get(keys.indexOf(p.getPropertyName())).getKeyId(), p.getPropertyValue(), now)).collect(Collectors.toList());
}
Also used : Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) AuditActions(org.broadinstitute.consent.http.enumeration.AuditActions) DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) HashMap(java.util.HashMap) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) DataUse(org.broadinstitute.consent.http.models.DataUse) ArrayList(java.util.ArrayList) DatasetDAO(org.broadinstitute.consent.http.db.DatasetDAO) Inject(javax.inject.Inject) HashSet(java.util.HashSet) DataSetAudit(org.broadinstitute.consent.http.models.DataSetAudit) Map(java.util.Map) DataSetPropertyDTO(org.broadinstitute.consent.http.models.dto.DataSetPropertyDTO) UserRoleDAO(org.broadinstitute.consent.http.db.UserRoleDAO) DataSetProperty(org.broadinstitute.consent.http.models.DataSetProperty) DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) DataSet(org.broadinstitute.consent.http.models.DataSet) Logger(org.slf4j.Logger) DataAccessRequestDAO(org.broadinstitute.consent.http.db.DataAccessRequestDAO) DataUseTranslationType(org.broadinstitute.consent.http.enumeration.DataUseTranslationType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) AssociationType(org.broadinstitute.consent.http.enumeration.AssociationType) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) ConsentDAO(org.broadinstitute.consent.http.db.ConsentDAO) Dictionary(org.broadinstitute.consent.http.models.Dictionary) UseRestriction(org.broadinstitute.consent.http.models.grammar.UseRestriction) Optional(java.util.Optional) Collections(java.util.Collections) Consent(org.broadinstitute.consent.http.models.Consent) Dictionary(org.broadinstitute.consent.http.models.Dictionary) DataSetProperty(org.broadinstitute.consent.http.models.DataSetProperty) Date(java.util.Date)

Aggregations

NotFoundException (javax.ws.rs.NotFoundException)2 Dictionary (org.broadinstitute.consent.http.models.Dictionary)2 DataSetPropertyDTO (org.broadinstitute.consent.http.models.dto.DataSetPropertyDTO)2 DatasetDTO (org.broadinstitute.consent.http.models.dto.DatasetDTO)2 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 PermitAll (javax.annotation.security.PermitAll)1 Inject (javax.inject.Inject)1