Search in sources :

Example 1 with DataverseTheme

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

the class Access method getLogo.

// helper methods:
// What the method below does - going through all the files in the version -
// is too expensive! Instead we are now selecting an available thumbnail and
// giving the dataset card a direct link to that file thumbnail. -- L.A., 4.2.2
/*
    private StorageIO getThumbnailForDatasetVersion(DatasetVersion datasetVersion) {
        logger.info("entering getThumbnailForDatasetVersion()");
        StorageIO thumbnailDataAccess = null;
        if (datasetVersion != null) {
            List<FileMetadata> fileMetadatas = datasetVersion.getFileMetadatas();

            for (FileMetadata fileMetadata : fileMetadatas) {
                DataFile dataFile = fileMetadata.getDataFile();
                logger.info("looking at file "+fileMetadata.getLabel()+" , file type "+dataFile.getContentType());

                if (dataFile != null && dataFile.isImage()) {

                    try {
                        StorageIO dataAccess = dataFile.getStorageIO();
                        if (dataAccess != null && dataAccess.isLocalFile()) {
                            dataAccess.open();

                            thumbnailDataAccess = ImageThumbConverter.getImageThumb((FileAccessIO) dataAccess, 48);
                        }
                    } catch (IOException ioEx) {
                        thumbnailDataAccess = null;
                    }
                }
                if (thumbnailDataAccess != null) {
                    logger.info("successfully generated thumbnail, returning.");
                    break;
                }
            }
        }
        return thumbnailDataAccess;
    }
    */
// TODO:
// put this method into the dataverseservice; use it there
// -- L.A. 4.0 beta14
private File getLogo(Dataverse dataverse) {
    if (dataverse.getId() == null) {
        return null;
    }
    DataverseTheme theme = dataverse.getDataverseTheme();
    if (theme != null && theme.getLogo() != null && !theme.getLogo().equals("")) {
        Properties p = System.getProperties();
        String domainRoot = p.getProperty("com.sun.aas.instanceRoot");
        if (domainRoot != null && !"".equals(domainRoot)) {
            return new File(domainRoot + File.separator + "docroot" + File.separator + "logos" + File.separator + dataverse.getLogoOwnerId() + File.separator + theme.getLogo());
        }
    }
    return null;
}
Also used : DataverseTheme(edu.harvard.iq.dataverse.DataverseTheme) Properties(java.util.Properties) DataFile(edu.harvard.iq.dataverse.DataFile) File(java.io.File)

Example 2 with DataverseTheme

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

the class JsonParser method parseDataverse.

public Dataverse parseDataverse(JsonObject jobj) throws JsonParseException {
    Dataverse dv = new Dataverse();
    /**
     * @todo Instead of this getMandatoryString method we should run the
     * String through ConstraintValidator. See EMailValidatorTest and
     * EMailValidator for examples. That way we can check not only if it's
     * required or not but other bean validation rules such as "must match
     * this regex".
     */
    dv.setAlias(getMandatoryString(jobj, "alias"));
    dv.setName(getMandatoryString(jobj, "name"));
    dv.setDescription(jobj.getString("description", null));
    dv.setPermissionRoot(jobj.getBoolean("permissionRoot", false));
    dv.setFacetRoot(jobj.getBoolean("facetRoot", false));
    dv.setAffiliation(jobj.getString("affiliation", null));
    if (jobj.containsKey("dataverseContacts")) {
        JsonArray dvContacts = jobj.getJsonArray("dataverseContacts");
        int i = 0;
        List<DataverseContact> dvContactList = new LinkedList<>();
        for (JsonValue jsv : dvContacts) {
            DataverseContact dvc = new DataverseContact(dv);
            dvc.setContactEmail(getMandatoryString((JsonObject) jsv, "contactEmail"));
            dvc.setDisplayOrder(i++);
            dvContactList.add(dvc);
        }
        dv.setDataverseContacts(dvContactList);
    }
    if (jobj.containsKey("theme")) {
        DataverseTheme theme = parseDataverseTheme(jobj.getJsonObject("theme"));
        dv.setDataverseTheme(theme);
        theme.setDataverse(dv);
    }
    // default
    dv.setDataverseType(Dataverse.DataverseType.UNCATEGORIZED);
    if (jobj.containsKey("dataverseType")) {
        for (Dataverse.DataverseType dvtype : Dataverse.DataverseType.values()) {
            if (dvtype.name().equals(jobj.getString("dataverseType"))) {
                dv.setDataverseType(dvtype);
            }
        }
    }
    return dv;
}
Also used : JsonArray(javax.json.JsonArray) DataverseTheme(edu.harvard.iq.dataverse.DataverseTheme) JsonValue(javax.json.JsonValue) DataverseContact(edu.harvard.iq.dataverse.DataverseContact) JsonObject(javax.json.JsonObject) Dataverse(edu.harvard.iq.dataverse.Dataverse) LinkedList(java.util.LinkedList)

Aggregations

DataverseTheme (edu.harvard.iq.dataverse.DataverseTheme)2 DataFile (edu.harvard.iq.dataverse.DataFile)1 Dataverse (edu.harvard.iq.dataverse.Dataverse)1 DataverseContact (edu.harvard.iq.dataverse.DataverseContact)1 File (java.io.File)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 JsonValue (javax.json.JsonValue)1