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