use of edu.harvard.iq.dataverse.DatasetFieldType in project dataverse by IQSS.
the class MocksFactory method makeDatasetFieldType.
public static DatasetFieldType makeDatasetFieldType() {
final Long id = nextId();
DatasetFieldType retVal = new DatasetFieldType("SampleType-" + id, FieldType.TEXT, false);
retVal.setId(id);
return retVal;
}
use of edu.harvard.iq.dataverse.DatasetFieldType 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.DatasetFieldType 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.DatasetFieldType in project dataverse by IQSS.
the class DatasetFieldServiceApi method getByName.
@GET
@Path("{name}")
public Response getByName(@PathParam("name") String name) {
try {
DatasetFieldType dsf = datasetFieldService.findByName(name);
Long id = dsf.getId();
String title = dsf.getTitle();
FieldType fieldType = dsf.getFieldType();
String solrFieldSearchable = dsf.getSolrField().getNameSearchable();
String solrFieldFacetable = dsf.getSolrField().getNameFacetable();
String metadataBlock = dsf.getMetadataBlock().getName();
boolean hasParent = dsf.isHasParent();
boolean allowsMultiples = dsf.isAllowMultiples();
boolean isRequired = dsf.isRequired();
String parentAllowsMultiplesDisplay = "N/A (no parent)";
boolean parentAllowsMultiplesBoolean;
if (hasParent) {
DatasetFieldType parent = dsf.getParentDatasetFieldType();
parentAllowsMultiplesBoolean = parent.isAllowMultiples();
parentAllowsMultiplesDisplay = Boolean.toString(parentAllowsMultiplesBoolean);
}
return ok(NullSafeJsonBuilder.jsonObjectBuilder().add("name", dsf.getName()).add("id", id).add("title", title).add("metadataBlock", metadataBlock).add("fieldType", fieldType.name()).add("allowsMultiples", allowsMultiples).add("hasParent", hasParent).add("parentAllowsMultiples", parentAllowsMultiplesDisplay).add("solrFieldSearchable", solrFieldSearchable).add("solrFieldFacetable", solrFieldFacetable).add("isRequired", isRequired));
} catch (NoResultException nre) {
return notFound(name);
} catch (EJBException | NullPointerException ex) {
Throwable cause = ex;
StringBuilder sb = new StringBuilder();
sb.append(ex).append(" ");
while (cause.getCause() != null) {
cause = cause.getCause();
sb.append(cause.getClass().getCanonicalName()).append(" ");
sb.append(cause.getMessage()).append(" ");
if (cause instanceof ConstraintViolationException) {
ConstraintViolationException constraintViolationException = (ConstraintViolationException) cause;
for (ConstraintViolation<?> violation : constraintViolationException.getConstraintViolations()) {
sb.append("(invalid value: <<<").append(violation.getInvalidValue()).append(">>> for ").append(violation.getPropertyPath()).append(" at ").append(violation.getLeafBean()).append(" - ").append(violation.getMessage()).append(")");
}
}
}
return error(Status.INTERNAL_SERVER_ERROR, sb.toString());
}
}
use of edu.harvard.iq.dataverse.DatasetFieldType in project dataverse by IQSS.
the class DatasetFieldServiceApi method getAll.
@GET
public Response getAll() {
try {
List<String> listOfIsHasParentsTrue = new ArrayList<>();
List<String> listOfIsHasParentsFalse = new ArrayList<>();
List<String> listOfIsAllowsMultiplesTrue = new ArrayList<>();
List<String> listOfIsAllowsMultiplesFalse = new ArrayList<>();
for (DatasetFieldType dsf : datasetFieldService.findAllOrderedById()) {
if (dsf.isHasParent()) {
listOfIsHasParentsTrue.add(dsf.getName());
listOfIsAllowsMultiplesTrue.add(dsf.getName());
} else {
listOfIsHasParentsFalse.add(dsf.getName());
listOfIsAllowsMultiplesFalse.add(dsf.getName());
}
}
final List<DatasetFieldType> requiredFields = datasetFieldService.findAllRequiredFields();
final List<String> requiredFieldNames = new ArrayList<>(requiredFields.size());
for (DatasetFieldType dt : requiredFields) {
requiredFieldNames.add(dt.getName());
}
return ok(Json.createObjectBuilder().add("haveParents", asJsonArray(listOfIsHasParentsTrue)).add("noParents", asJsonArray(listOfIsHasParentsFalse)).add("allowsMultiples", asJsonArray(listOfIsAllowsMultiplesTrue)).add("allowsMultiples", asJsonArray(listOfIsAllowsMultiplesTrue)).add("doesNotAllowMultiples", asJsonArray(listOfIsAllowsMultiplesFalse)).add("required", asJsonArray(requiredFieldNames)));
} catch (EJBException ex) {
Throwable cause = ex;
StringBuilder sb = new StringBuilder();
sb.append(ex).append(" ");
while (cause.getCause() != null) {
cause = cause.getCause();
sb.append(cause.getClass().getCanonicalName()).append(" ");
sb.append(cause.getMessage()).append(" ");
if (cause instanceof ConstraintViolationException) {
ConstraintViolationException constraintViolationException = (ConstraintViolationException) cause;
for (ConstraintViolation<?> violation : constraintViolationException.getConstraintViolations()) {
sb.append("(invalid value: <<<").append(violation.getInvalidValue()).append(">>> for ").append(violation.getPropertyPath()).append(" at ").append(violation.getLeafBean()).append(" - ").append(violation.getMessage()).append(")");
}
}
}
return error(Status.INTERNAL_SERVER_ERROR, sb.toString());
}
}
Aggregations