Search in sources :

Example 1 with IIdentifiableEntity

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());
}
Also used : IIdentifiableEntity(eu.etaxonomy.cdm.model.common.IIdentifiableEntity) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test)

Example 2 with IIdentifiableEntity

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();
}
Also used : Query(org.hibernate.Query) IIdentifiableEntity(eu.etaxonomy.cdm.model.common.IIdentifiableEntity)

Example 3 with IIdentifiableEntity

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) ModelAndView(org.springframework.web.servlet.ModelAndView) LSIDServerException(com.ibm.lsid.server.LSIDServerException) Vector(java.util.Vector) IIdentifiableEntity(eu.etaxonomy.cdm.model.common.IIdentifiableEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with IIdentifiableEntity

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());
    }
}
Also used : LSIDException(com.ibm.lsid.LSIDException) ByteArrayInputStream(java.io.ByteArrayInputStream) LSIDServerException(com.ibm.lsid.server.LSIDServerException) IIdentifiableEntity(eu.etaxonomy.cdm.model.common.IIdentifiableEntity)

Aggregations

IIdentifiableEntity (eu.etaxonomy.cdm.model.common.IIdentifiableEntity)4 LSIDServerException (com.ibm.lsid.server.LSIDServerException)2 LSIDException (com.ibm.lsid.LSIDException)1 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringTokenizer (java.util.StringTokenizer)1 Vector (java.util.Vector)1 Query (org.hibernate.Query)1 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1