Search in sources :

Example 1 with DatasetFieldType

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;
}
Also used : DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType)

Example 2 with DatasetFieldType

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;
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) Dataverse(edu.harvard.iq.dataverse.Dataverse) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType)

Example 3 with DatasetFieldType

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);
    }
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) ArrayList(java.util.ArrayList) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType)

Example 4 with DatasetFieldType

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());
    }
}
Also used : NoResultException(javax.persistence.NoResultException) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) FieldType(edu.harvard.iq.dataverse.DatasetFieldType.FieldType) ConstraintViolation(javax.validation.ConstraintViolation) ConstraintViolationException(javax.validation.ConstraintViolationException) EJBException(javax.ejb.EJBException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 5 with DatasetFieldType

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());
    }
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) ConstraintViolationException(javax.validation.ConstraintViolationException) EJBException(javax.ejb.EJBException) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) GET(javax.ws.rs.GET)

Aggregations

DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)41 DatasetField (edu.harvard.iq.dataverse.DatasetField)16 ControlledVocabularyValue (edu.harvard.iq.dataverse.ControlledVocabularyValue)12 DatasetFieldCompoundValue (edu.harvard.iq.dataverse.DatasetFieldCompoundValue)9 ArrayList (java.util.ArrayList)9 JsonObject (javax.json.JsonObject)7 Dataverse (edu.harvard.iq.dataverse.Dataverse)6 LinkedList (java.util.LinkedList)6 Test (org.junit.Test)6 MetadataBlock (edu.harvard.iq.dataverse.MetadataBlock)5 EJBException (javax.ejb.EJBException)5 Path (javax.ws.rs.Path)5 DatasetFieldValue (edu.harvard.iq.dataverse.DatasetFieldValue)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 NoResultException (javax.persistence.NoResultException)4 GET (javax.ws.rs.GET)4 Before (org.junit.Before)4 DataverseFieldTypeInputLevel (edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)3 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)3