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;
}
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);
}
}
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();
}
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();
}
}
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();
}
}
Aggregations