Search in sources :

Example 36 with OrcidProfile

use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.

the class RDFMessageBodyWriter method writeTo.

/**
     * Write a type to an HTTP response. The response header map is mutable but
     * any changes must be made before writing to the output stream since the
     * headers will be flushed prior to writing the response body.
     * 
     * @param message
     *            the instance to write.
     * @param type
     *            the class of object that is to be written.
     * @param genericType
     *            the type of object to be written, obtained either by
     *            reflection of a resource method return type or by inspection
     *            of the returned instance.
     *            {@link javax.ws.rs.core.GenericEntity} provides a way to
     *            specify this information at runtime.
     * @param annotations
     *            an array of the annotations on the resource method that
     *            returns the object.
     * @param mediaType
     *            the media type of the HTTP entity.
     * @param httpHeaders
     *            a mutable map of the HTTP response headers.
     * @param entityStream
     *            the {@link java.io.OutputStream} for the HTTP entity. The
     *            implementation should not close the output stream.
     * @throws java.io.IOException
     *             if an IO error arises
     * @throws javax.ws.rs.WebApplicationException
     *             if a specific HTTP error response needs to be produced. Only
     *             effective if thrown prior to the response being committed.
     */
@Override
public void writeTo(OrcidMessage xml, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    OntModel m = getOntModel();
    if (xml.getErrorDesc() != null) {
        describeError(xml.getErrorDesc(), m);
    }
    OrcidProfile orcidProfile = xml.getOrcidProfile();
    // System.out.println(httpHeaders);
    Individual profileDoc = null;
    if (orcidProfile != null) {
        Individual person = describePerson(orcidProfile, m);
        if (person != null) {
            profileDoc = describeAccount(orcidProfile, m, person);
        }
    }
    MediaType jsonLd = new MediaType("application", "ld+json");
    MediaType nTriples = new MediaType("application", "n-triples");
    MediaType rdfXml = new MediaType("application", "rdf+xml");
    String base = null;
    if (getUriInfo() != null) {
        getUriInfo().getAbsolutePath().toASCIIString();
    }
    if (mediaType.isCompatible(nTriples)) {
        // NOTE: N-Triples requires absolute URIs
        m.write(entityStream, "N-TRIPLES");
    } else if (mediaType.isCompatible(jsonLd)) {
        m.write(entityStream, "JSON-LD", base);
    } else if (mediaType.isCompatible(rdfXml)) {
        m.write(entityStream, "RDF/XML", base);
    } else {
        // Turtle is the safest default        	
        m.write(entityStream, "TURTLE", base);
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Individual(org.apache.jena.ontology.Individual) OntModel(org.apache.jena.ontology.OntModel) MediaType(javax.ws.rs.core.MediaType)

Example 37 with OrcidProfile

use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method updateSecurityQuestionInformation.

@Override
public void updateSecurityQuestionInformation(OrcidProfile updatedOrcidProfile) {
    String orcid = updatedOrcidProfile.getOrcidIdentifier().getPath();
    SecurityQuestionId securityQuestionId = updatedOrcidProfile.getOrcidInternal().getSecurityDetails().getSecurityQuestionId();
    Integer questionId = null;
    if (securityQuestionId != null) {
        questionId = new Long(securityQuestionId.getValue()).intValue();
    }
    String unencryptedAnswer = updatedOrcidProfile.getSecurityQuestionAnswer();
    String encryptedAnswer = encrypt(unencryptedAnswer);
    profileDao.updateSecurityQuestion(orcid, questionId, questionId != null ? encryptedAnswer : null);
    OrcidProfile cachedProfile = orcidProfileCacheManager.retrieve(orcid);
    if (cachedProfile != null) {
        profileDao.flush();
        SecurityDetails securityDetails = initSecurityDetails(cachedProfile);
        securityDetails.setSecurityQuestionId(questionId != null ? new SecurityQuestionId(questionId) : null);
        securityDetails.setEncryptedSecurityAnswer(encryptedAnswer != null ? new EncryptedSecurityAnswer(encryptedAnswer) : null);
        cachedProfile.setSecurityQuestionAnswer(encryptedAnswer != null ? unencryptedAnswer : null);
        orcidProfileCacheManager.put(cachedProfile);
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) EncryptedSecurityAnswer(org.orcid.jaxb.model.message.EncryptedSecurityAnswer) SecurityDetails(org.orcid.jaxb.model.message.SecurityDetails) SecurityQuestionId(org.orcid.jaxb.model.message.SecurityQuestionId)

Example 38 with OrcidProfile

use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method reactivateOrcidProfile.

/**
     * Reactivate an inactive profile
     * */
public OrcidProfile reactivateOrcidProfile(OrcidProfile deactivatedOrcidProfile) {
    OrcidHistory deactivatedOrcidHistory = deactivatedOrcidProfile.getOrcidHistory();
    deactivatedOrcidHistory.setDeactivationDate(null);
    OrcidProfile profileToReturn = updateOrcidProfile(deactivatedOrcidProfile);
    notificationManager.sendAmendEmail(profileToReturn, AmendedSection.UNKNOWN);
    return profileToReturn;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory)

Example 39 with OrcidProfile

use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.

the class OrcidProfileManagerReadOnlyImpl method doRetrieveFreshOrcidProfileInTransaction.

private OrcidProfile doRetrieveFreshOrcidProfileInTransaction(String orcid, LoadOptions loadOptions) {
    LOG.debug("About to obtain fresh profile: " + orcid);
    profileDao.flushWithoutTransactional();
    ProfileEntity profileEntity = profileDao.find(orcid);
    if (profileEntity != null) {
        OrcidProfile freshOrcidProfile = convertToOrcidProfile(profileEntity, loadOptions);
        return freshOrcidProfile;
    }
    return null;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 40 with OrcidProfile

use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.

the class OrcidSearchManagerImpl method findPublicProfileById.

@Override
public OrcidMessage findPublicProfileById(String orcid) {
    OrcidMessage om = null;
    try {
        if (cachingSource.equals(DB)) {
            OrcidProfile orcidProfile = orcidProfileCacheManager.retrievePublic(orcid);
            orcidProfile.setOrcidInternal(null);
            om = new OrcidMessage(orcidProfile);
        } else {
            try (Reader reader = solrDao.findByOrcidAsReader(orcid)) {
                if (reader != null) {
                    BufferedReader br = new BufferedReader(reader);
                    om = OrcidMessage.unmarshall(br);
                }
            }
        }
    } catch (NonTransientDataAccessResourceException e) {
        throw new OrcidSearchException("Error searching by id: " + orcid, e);
    } catch (IOException e) {
        throw new OrcidSearchException("Error closing stream for id: " + orcid, e);
    }
    if (om == null)
        throw new OrcidSearchException("Result is null");
    return om;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) OrcidSearchException(org.orcid.core.exception.OrcidSearchException) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Aggregations

OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)241 Test (org.junit.Test)118 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)77 Transactional (org.springframework.transaction.annotation.Transactional)50 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)45 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)43 DBUnitTest (org.orcid.test.DBUnitTest)43 Rollback (org.springframework.test.annotation.Rollback)40 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)36 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)35 Date (java.util.Date)27 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)27 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)25 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)23 Affiliations (org.orcid.jaxb.model.message.Affiliations)22 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)22 Title (org.orcid.jaxb.model.message.Title)22 Email (org.orcid.jaxb.model.message.Email)21 GivenNames (org.orcid.jaxb.model.message.GivenNames)21 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)21