Search in sources :

Example 1 with TmetadataImpl

use of org.eclipse.kapua.commons.configuration.metatype.TmetadataImpl in project kapua by eclipse.

the class AbstractKapuaConfigurableService method readMetadata.

private static TmetadataImpl readMetadata(String pid) throws IOException, Exception, XMLStreamException, FactoryConfigurationError {
    TmetadataImpl metaData = null;
    StringBuilder sbMetatypeXmlName = new StringBuilder();
    sbMetatypeXmlName.append("META-INF/metatypes/").append(pid).append(".xml");
    String metatypeXmlName = sbMetatypeXmlName.toString();
    URL metatypeXmlURL = ResourceUtils.getResource(metatypeXmlName);
    String metatypeXml = ResourceUtils.readResource(metatypeXmlURL);
    if (metatypeXml != null) {
        metaData = XmlUtil.unmarshal(metatypeXml, TmetadataImpl.class);
    }
    return metaData;
}
Also used : TmetadataImpl(org.eclipse.kapua.commons.configuration.metatype.TmetadataImpl) URL(java.net.URL)

Example 2 with TmetadataImpl

use of org.eclipse.kapua.commons.configuration.metatype.TmetadataImpl in project kapua by eclipse.

the class AbstractKapuaConfigurableService method getConfigMetadata.

@Override
public KapuaTocd getConfigMetadata() throws KapuaException {
    KapuaLocator locator = KapuaLocator.getInstance();
    AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
    PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
    KapuaId scopeId = KapuaSecurityUtils.getSession().getScopeId();
    authorizationService.checkPermission(permissionFactory.newPermission(domain, Actions.read, scopeId));
    try {
        TmetadataImpl metadata = readMetadata(this.pid);
        if (metadata.getOCD() != null && metadata.getOCD().size() > 0) {
            for (KapuaTocd ocd : metadata.getOCD()) {
                if (ocd.getId() != null && ocd.getId().equals(pid)) {
                    return ocd;
                }
            }
        }
        return null;
    } catch (Exception e) {
        throw KapuaConfigurationException.internalError(e);
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) KapuaId(org.eclipse.kapua.model.id.KapuaId) TmetadataImpl(org.eclipse.kapua.commons.configuration.metatype.TmetadataImpl) KapuaTocd(org.eclipse.kapua.model.config.metatype.KapuaTocd) XMLStreamException(javax.xml.stream.XMLStreamException) KapuaEntityNotFoundException(org.eclipse.kapua.KapuaEntityNotFoundException) IOException(java.io.IOException) KapuaException(org.eclipse.kapua.KapuaException)

Aggregations

TmetadataImpl (org.eclipse.kapua.commons.configuration.metatype.TmetadataImpl)2 IOException (java.io.IOException)1 URL (java.net.URL)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)1 KapuaException (org.eclipse.kapua.KapuaException)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 KapuaTocd (org.eclipse.kapua.model.config.metatype.KapuaTocd)1 KapuaId (org.eclipse.kapua.model.id.KapuaId)1 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)1 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)1