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