use of eu.etaxonomy.cdm.model.common.IIdentifiableEntity in project cdmlib by cybertaxonomy.
the class LSIDMetadataServiceTest method testGetMetadataWithKnownLSID.
@Test
public void testGetMetadataWithKnownLSID() throws Exception {
IIdentifiableEntity identifiableEntity = lsidMetadataService.getMetadata(lsid);
assertNotNull("getMetadata should return an IdentifiableEntity", identifiableEntity);
assertEquals("the object should have an lsid equal to the lsid supplied", lsid.getAuthority(), identifiableEntity.getLsid().getAuthority());
assertEquals("the object should have an lsid equal to the lsid supplied", lsid.getNamespace(), identifiableEntity.getLsid().getNamespace());
assertEquals("the object should have an lsid equal to the lsid supplied", lsid.getObject(), identifiableEntity.getLsid().getObject());
}
use of eu.etaxonomy.cdm.model.common.IIdentifiableEntity in project cdmlib by cybertaxonomy.
the class LsidAuthorityDaoImpl method getClassForNamespace.
public Class<? extends IIdentifiableEntity> getClassForNamespace(LSID lsid) {
Query query = getSession().createQuery("select clazz from LSIDAuthority authority join authority.namespaces clazz where authority.authority = :authority and index(clazz) = :namespace");
query.setParameter("authority", lsid.getAuthority());
query.setParameter("namespace", lsid.getNamespace());
return (Class<? extends IIdentifiableEntity>) query.uniqueResult();
}
use of eu.etaxonomy.cdm.model.common.IIdentifiableEntity in project cdmlib by cybertaxonomy.
the class MetadataController method getMetadata.
/**
* Handle requests for the metadata representation of an object with a given lsid. Will return metadata in any format supported
* from a list of formats if specified.
*
* @param lsid the lsid to get metadata for
* @param formats a comma separated list of acceptable formats to the client
* @return ModelAndView containing the metadata response as an object with key 'metadataResponse', view name 'Metadata.rdf'
* @throws LSIDServerException
*/
@RequestMapping(value = "/authority/metadata.do", params = "lsid", method = RequestMethod.GET)
public ModelAndView getMetadata(@RequestParam("lsid") LSID lsid, @RequestParam(value = "acceptedFormats", required = false) String formats) throws LSIDServerException {
String[] acceptedFormats = null;
if (formats != null) {
StringTokenizer st = new StringTokenizer(formats, ",", false);
Vector<String> v = new Vector<String>();
while (st.hasMoreTokens()) {
v.add(st.nextToken());
}
acceptedFormats = new String[v.size()];
v.toArray(acceptedFormats);
}
if (acceptedFormats != null) {
boolean found = false;
for (int i = 0; i < acceptedFormats.length; i++) {
if (acceptedFormats[i].equals(MetadataResponse.RDF_FORMAT)) {
found = true;
}
break;
}
if (!found) {
throw new LSIDServerException(LSIDServerException.NO_METADATA_AVAILABLE_FOR_FORMATS, "No metadata found for given format");
}
}
IIdentifiableEntity identifiableEntity = lsidMetadataService.getMetadata(lsid);
ModelAndView modelAndView = new ModelAndView("Metadata.rdf");
modelAndView.addObject(identifiableEntity);
return modelAndView;
}
use of eu.etaxonomy.cdm.model.common.IIdentifiableEntity in project cdmlib by cybertaxonomy.
the class LsidDataServiceImpl method getDataByRange.
public InputStream getDataByRange(LSID lsid, Integer start, Integer length) throws LSIDServerException {
IIdentifiableDao<?> identfiableDAO = lsidRegistry.lookupDAO(lsid);
if (identfiableDAO == null) {
// we do not have a mapping for lsids with this authority or namespace
throw new LSIDServerException(LSIDException.UNKNOWN_LSID, "Unknown LSID");
}
try {
IIdentifiableEntity i = identfiableDAO.find(lsid);
if (i == null) {
// we have a mapping for lsids with this authority and namespace, but no lsid stored
throw new LSIDServerException(LSIDException.UNKNOWN_LSID, "Unknown LSID");
}
if (i.getData() != null) {
byte[] subset = new byte[length];
System.arraycopy(i.getData(), start, subset, 0, length);
return new ByteArrayInputStream(subset);
} else {
return null;
}
} catch (LSIDException e) {
throw new LSIDServerException(e, e.getErrorCode(), e.getMessage());
}
}
Aggregations