Search in sources :

Example 1 with MetadataBlock

use of edu.harvard.iq.dataverse.MetadataBlock in project dataverse by IQSS.

the class MocksFactory method makeDataverse.

public static Dataverse makeDataverse() {
    Dataverse retVal = new Dataverse();
    retVal.setId(nextId());
    retVal.setAffiliation("Unit Test U");
    retVal.setAlias("unitTest" + retVal.getId());
    retVal.setCreateDate(timestamp(2012, 4, 5));
    retVal.setMetadataBlockRoot(true);
    retVal.setName("UnitTest Dataverse #" + retVal.getId());
    MetadataBlock mtb = new MetadataBlock();
    mtb.setDisplayName("Test Block #1-" + retVal.getId());
    mtb.setId(nextId());
    mtb.setDatasetFieldTypes(Arrays.asList(new DatasetFieldType("JustAString", DatasetFieldType.FieldType.TEXT, false), new DatasetFieldType("ManyStrings", DatasetFieldType.FieldType.TEXT, true), new DatasetFieldType("AnEmail", DatasetFieldType.FieldType.EMAIL, false)));
    retVal.setMetadataBlocks(Arrays.asList(mtb));
    return retVal;
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) Dataverse(edu.harvard.iq.dataverse.Dataverse) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType)

Example 2 with MetadataBlock

use of edu.harvard.iq.dataverse.MetadataBlock in project dataverse by IQSS.

the class AdvancedSearchPage method init.

public void init() {
    if (dataverseIdentifier != null) {
        dataverse = dataverseServiceBean.findByAlias(dataverseIdentifier);
    }
    if (dataverse == null) {
        dataverse = dataverseServiceBean.findRootDataverse();
    }
    metadataBlocks = dataverse.getMetadataBlocks();
    this.metadataFieldList = datasetFieldService.findAllAdvancedSearchFieldTypes();
    for (MetadataBlock mdb : metadataBlocks) {
        List<DatasetFieldType> dsfTypes = new ArrayList<>();
        for (DatasetFieldType dsfType : metadataFieldList) {
            if (dsfType.getMetadataBlock().getId().equals(mdb.getId())) {
                dsfTypes.add(dsfType);
            }
        }
        metadataFieldMap.put(mdb.getId(), dsfTypes);
    }
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) ArrayList(java.util.ArrayList) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType)

Example 3 with MetadataBlock

use of edu.harvard.iq.dataverse.MetadataBlock in project dataverse by IQSS.

the class DatasetFieldServiceApi method parseMetadataBlock.

private String parseMetadataBlock(String[] values) {
    // Test to see if it exists by name
    MetadataBlock mdb = metadataBlockService.findByName(values[1]);
    if (mdb == null) {
        mdb = new MetadataBlock();
    }
    mdb.setName(values[1]);
    if (!values[2].isEmpty()) {
        mdb.setOwner(dataverseService.findByAlias(values[2]));
    }
    mdb.setDisplayName(values[3]);
    metadataBlockService.save(mdb);
    return mdb.getName();
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock)

Example 4 with MetadataBlock

use of edu.harvard.iq.dataverse.MetadataBlock in project dataverse by IQSS.

the class Dataverses method listMetadataBlocks.

@GET
@Path("{identifier}/metadatablocks")
public Response listMetadataBlocks(@PathParam("identifier") String dvIdtf) {
    try {
        JsonArrayBuilder arr = Json.createArrayBuilder();
        final List<MetadataBlock> blocks = execCommand(new ListMetadataBlocksCommand(createDataverseRequest(findUserOrDie()), findDataverseOrDie(dvIdtf)));
        for (MetadataBlock mdb : blocks) {
            arr.add(brief.json(mdb));
        }
        return allowCors(ok(arr));
    } catch (WrappedResponse we) {
        return we.getResponse();
    }
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) ListMetadataBlocksCommand(edu.harvard.iq.dataverse.engine.command.impl.ListMetadataBlocksCommand) JsonArrayBuilder(javax.json.JsonArrayBuilder) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 5 with MetadataBlock

use of edu.harvard.iq.dataverse.MetadataBlock in project dataverse by IQSS.

the class Dataverses method setMetadataBlocks.

@POST
@Path("{identifier}/metadatablocks")
@Produces(MediaType.APPLICATION_JSON)
public Response setMetadataBlocks(@PathParam("identifier") String dvIdtf, String blockIds) {
    List<MetadataBlock> blocks = new LinkedList<>();
    try {
        for (JsonValue blockId : Util.asJsonArray(blockIds).getValuesAs(JsonValue.class)) {
            MetadataBlock blk = (blockId.getValueType() == ValueType.NUMBER) ? findMetadataBlock(((JsonNumber) blockId).longValue()) : findMetadataBlock(((JsonString) blockId).getString());
            if (blk == null) {
                return error(Response.Status.BAD_REQUEST, "Can't find metadata block '" + blockId + "'");
            }
            blocks.add(blk);
        }
    } catch (Exception e) {
        return error(Response.Status.BAD_REQUEST, e.getMessage());
    }
    try {
        execCommand(new UpdateDataverseMetadataBlocksCommand.SetBlocks(createDataverseRequest(findUserOrDie()), findDataverseOrDie(dvIdtf), blocks));
        return ok("Metadata blocks of dataverse " + dvIdtf + " updated.");
    } catch (WrappedResponse ex) {
        return ex.getResponse();
    }
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) JsonNumber(javax.json.JsonNumber) JsonValue(javax.json.JsonValue) JsonString(javax.json.JsonString) LinkedList(java.util.LinkedList) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) EJBException(javax.ejb.EJBException) JsonParsingException(javax.json.stream.JsonParsingException) ConstraintViolationException(javax.validation.ConstraintViolationException) UpdateDataverseMetadataBlocksCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseMetadataBlocksCommand) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

MetadataBlock (edu.harvard.iq.dataverse.MetadataBlock)10 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 DatasetField (edu.harvard.iq.dataverse.DatasetField)3 DatasetFieldCompoundValue (edu.harvard.iq.dataverse.DatasetFieldCompoundValue)3 JsonObject (javax.json.JsonObject)3 Test (org.junit.Test)3 Path (javax.ws.rs.Path)2 ControlledVocabularyValue (edu.harvard.iq.dataverse.ControlledVocabularyValue)1 DatasetFieldValue (edu.harvard.iq.dataverse.DatasetFieldValue)1 Dataverse (edu.harvard.iq.dataverse.Dataverse)1 ListMetadataBlocksCommand (edu.harvard.iq.dataverse.engine.command.impl.ListMetadataBlocksCommand)1 UpdateDataverseMetadataBlocksCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDataverseMetadataBlocksCommand)1 SettingsServiceBean (edu.harvard.iq.dataverse.settings.SettingsServiceBean)1 JsonParseException (edu.harvard.iq.dataverse.util.json.JsonParseException)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1