Search in sources :

Example 1 with NamespaceIdOptionalName

use of org.eclipse.winery.common.beans.NamespaceIdOptionalName in project winery by eclipse.

the class WineryRepositoryClient method getQNameListOfAllTypes.

@Override
public <T extends TExtensibleElements> List<QName> getQNameListOfAllTypes(Class<T> className) {
    String path = Util.getURLpathFragmentForCollection(className);
    Map<WebResource, List<NamespaceIdOptionalName>> wRtoNamespaceAndIdListMapOfAllTypes = this.getWRtoNamespaceAndIdListMapOfAllTypes(path);
    Collection<List<NamespaceIdOptionalName>> namespaceAndIdListCollection = wRtoNamespaceAndIdListMapOfAllTypes.values();
    List<QName> res = new ArrayList<QName>(namespaceAndIdListCollection.size());
    for (List<NamespaceIdOptionalName> namespaceAndIdList : namespaceAndIdListCollection) {
        for (NamespaceIdOptionalName namespaceAndId : namespaceAndIdList) {
            QName qname = new QName(namespaceAndId.getNamespace(), namespaceAndId.getId());
            res.add(qname);
        }
    }
    return res;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) NamespaceIdOptionalName(org.eclipse.winery.common.beans.NamespaceIdOptionalName) WebResource(com.sun.jersey.api.client.WebResource) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 2 with NamespaceIdOptionalName

use of org.eclipse.winery.common.beans.NamespaceIdOptionalName in project winery by eclipse.

the class WineryRepositoryClient method getAllTypes.

/**
 * Fetches java objects at a given URL
 *
 * @param path      the path to use. E.g., "nodetypes" for node types, ...
 * @param className the class of the expected return type. May be TDefinitions or TEntityType. TDefinitions the mode
 *                  is that the import statement are recursively resolved and added to the returned Defintitions
 *                  elment
 */
// we convert an object to T if it T is definitions
// does not work without compiler error
@SuppressWarnings("unchecked")
private <T extends TExtensibleElements> Collection<T> getAllTypes(String path, Class<T> className) {
    Map<WebResource, List<NamespaceIdOptionalName>> wrToNamespaceAndIdListMapOfAllTypes = this.getWRtoNamespaceAndIdListMapOfAllTypes(path);
    // now we now all QNames. We have to fetch the full content now
    Collection<T> res = new LinkedList<T>();
    for (WebResource wr : wrToNamespaceAndIdListMapOfAllTypes.keySet()) {
        WebResource componentListResource = wr.path(path);
        for (NamespaceIdOptionalName nsAndId : wrToNamespaceAndIdListMapOfAllTypes.get(wr)) {
            TDefinitions definitions = WineryRepositoryClient.getDefinitions(componentListResource, nsAndId.getNamespace(), nsAndId.getId());
            if (definitions == null) {
                // try next one
                continue;
            }
            T result;
            if (TDefinitions.class.equals(className)) {
                // mode: complete definitions
                result = (T) definitions;
            } else {
                // convention: first element in list is the element we look for
                if (definitions.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().isEmpty()) {
                    result = null;
                    LOGGER.error("Type {}/{} was found, but did not return any data", nsAndId.getNamespace(), nsAndId.getId());
                } else {
                    LOGGER.trace("Probably found valid data for {}/{}", nsAndId.getNamespace(), nsAndId.getId());
                    result = (T) definitions.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().get(0);
                // caching disabled as we also handle TServiceTemplates
                // this.cache((TEntityType) result, new QName(nsAndId.getNamespace(), nsAndId.getId()));
                }
            }
            // than the element to insert.
            if (result != null) {
                res.add(result);
            }
        }
    }
    return res;
}
Also used : NamespaceIdOptionalName(org.eclipse.winery.common.beans.NamespaceIdOptionalName) WebResource(com.sun.jersey.api.client.WebResource) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) LinkedList(java.util.LinkedList)

Example 3 with NamespaceIdOptionalName

use of org.eclipse.winery.common.beans.NamespaceIdOptionalName in project winery by eclipse.

the class WineryRepositoryClient method getListOfAllInstances.

@Override
public Collection<QNameWithName> getListOfAllInstances(Class<? extends DefinitionsChildId> clazz) {
    // inspired by getQNameListOfAllTypes
    String path = Util.getRootPathFragment(clazz);
    Map<WebResource, List<NamespaceIdOptionalName>> wRtoNamespaceAndIdListMapOfAllTypes = this.getWRtoNamespaceAndIdListMapOfAllTypes(path);
    Collection<List<NamespaceIdOptionalName>> namespaceAndIdListCollection = wRtoNamespaceAndIdListMapOfAllTypes.values();
    List<QNameWithName> res = new ArrayList<QNameWithName>(namespaceAndIdListCollection.size());
    for (List<NamespaceIdOptionalName> namespaceAndIdList : namespaceAndIdListCollection) {
        for (NamespaceIdOptionalName namespaceAndId : namespaceAndIdList) {
            QNameWithName qn = new QNameWithName();
            qn.qname = new QName(namespaceAndId.getNamespace(), namespaceAndId.getId());
            qn.name = namespaceAndId.getName();
            res.add(qn);
        }
    }
    return res;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) NamespaceIdOptionalName(org.eclipse.winery.common.beans.NamespaceIdOptionalName) WebResource(com.sun.jersey.api.client.WebResource) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) QNameWithName(org.eclipse.winery.common.interfaces.QNameWithName)

Example 4 with NamespaceIdOptionalName

use of org.eclipse.winery.common.beans.NamespaceIdOptionalName in project winery by eclipse.

the class WineryRepositoryClient method getWRtoNamespaceAndIdListMapOfAllTypes.

/**
 * Base method for getQNameListOfAllTypes and getAllTypes.
 */
private <T extends TExtensibleElements> Map<WebResource, List<NamespaceIdOptionalName>> getWRtoNamespaceAndIdListMapOfAllTypes(String path) {
    Map<WebResource, List<NamespaceIdOptionalName>> res = new HashMap<WebResource, List<NamespaceIdOptionalName>>();
    for (WebResource wr : this.repositoryResources) {
        WebResource componentListResource = wr.path(path);
        // this could be parsed using JAXB
        // (http://jersey.java.net/nonav/documentation/latest/json.html),
        // but we are short in time, so we do a quick hack
        // The result also contains the optional name
        String idList = componentListResource.accept(MediaType.APPLICATION_JSON).get(String.class);
        LOGGER.trace(idList);
        List<NamespaceIdOptionalName> nsAndIdList;
        try {
            nsAndIdList = this.mapper.readValue(idList, new TypeReference<List<NamespaceIdOptionalName>>() {
            });
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            continue;
        }
        res.put(wr, nsAndIdList);
    }
    return res;
}
Also used : HashMap(java.util.HashMap) NamespaceIdOptionalName(org.eclipse.winery.common.beans.NamespaceIdOptionalName) WebResource(com.sun.jersey.api.client.WebResource) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) QNameAlreadyExistsException(org.eclipse.winery.common.interfaces.QNameAlreadyExistsException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

WebResource (com.sun.jersey.api.client.WebResource)4 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 NamespaceIdOptionalName (org.eclipse.winery.common.beans.NamespaceIdOptionalName)4 QName (javax.xml.namespace.QName)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 JAXBException (javax.xml.bind.JAXBException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 QNameAlreadyExistsException (org.eclipse.winery.common.interfaces.QNameAlreadyExistsException)1 QNameWithName (org.eclipse.winery.common.interfaces.QNameWithName)1 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)1 SAXException (org.xml.sax.SAXException)1