diff options
author | Stone, Avi (as206k) <as206k@att.com> | 2018-05-23 11:21:11 +0300 |
---|---|---|
committer | Stone, Avi (as206k) <as206k@att.com> | 2018-05-23 11:30:13 +0300 |
commit | 3e4c18770957b55e2f80da32c3a32caa908f1386 (patch) | |
tree | 8a94c656300e75e38febfe9826ad36fc54fe14f5 /dcaedt_catalog/api | |
parent | da9db1b89e8c9199da4791a2ccd26d1628120a08 (diff) |
Upgrade dt-be-main
Update sources for dcae-dt-be-main to latest version
Change-Id: I3d58a2dc32611c0ca90f1c97e1294a17d5748623
Issue-ID: SDC-1359
Signed-off-by: Stone, Avi (as206k) <as206k@att.com>
Diffstat (limited to 'dcaedt_catalog/api')
3 files changed, 346 insertions, 534 deletions
diff --git a/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/Catalog.java b/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/Catalog.java index b73bb09..c9813e4 100644 --- a/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/Catalog.java +++ b/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/Catalog.java @@ -2,14 +2,8 @@ package org.onap.sdc.dcae.catalog; import java.net.URI; -import java.util.Arrays; -import java.util.Collection; import java.util.Iterator; -import java.util.List; -import java.util.Map; import java.util.LinkedList; -import java.util.HashMap; -import java.util.EnumSet; import org.json.JSONObject; import org.onap.sdc.dcae.catalog.commons.Action; @@ -20,421 +14,258 @@ import org.onap.sdc.dcae.catalog.commons.Proxies; import org.json.JSONArray; -/* - * - */ public interface Catalog { - public abstract URI getUri(); - - public abstract String namespace(); - - public abstract boolean same(Catalog theCatalog); - - public abstract <T> T proxy(JSONObject theData, Class<T> theType); - - - /* Base class for all Catalog objects. - */ - public static interface Element<T extends Element<T>> { - - /** - * provide a typed 'self' reference - */ - public default T self() { return (T)this; } - - /** - */ - public default Class<T> selfClass() { - return (Class<T>)getClass().getInterfaces()[0]; - } - - /* */ - public Catalog catalog(); - - /** - */ - public String id(); - - /** - * Direct access to the underlying JSON object. - * Warning: Modifications to the JSON object are reflected in the Element. - */ - public JSONObject data(); - - /** - * Provides the labels of the artifacts (we use labels to type/classify the - * neo4j artifacts, nodes and edges. - * Currently not all queries retrieve the labels. - */ - public String[] labels(); - - /* Allows for typed deep exploration of the backing JSON data structure - * <pre> - * {@code - * element("type", Type.class); - * } - * </pre> - * - * @arg theName name of a JSON entry ; It must map another JSONObject. - * @arg theType the expected wrapping catalog artifact type - * @return the JSON entry wrapped in the specified type - */ - public default <E extends Element<E>> E element(String theName, Class<E> theType) { - JSONObject elemData = data().optJSONObject(theName); - if (elemData == null) - return null; - else - return catalog().proxy(elemData, theType); - } - - /* Similar to {@link #element(String,Class)} but for collection wrapping. - * Example: - * <pre> - * {@code - * element("nodes", Nodes.class); - * } - * </pre> - */ - public default <E extends Elements> E elements(String theName, Class<E> theType) { - //throws ReflectiveOperationException { - JSONArray elemsData = data().optJSONArray(theName); - if (elemsData == null) { - return null; - } - else { - Class etype = Proxies.typeArgument(theType); - Elements elems = null; - try { - elems = theType.newInstance(); - } - catch (ReflectiveOperationException rox) { - throw new RuntimeException("Failed to instantiate " + theType, rox); - } - - try{ - for (Iterator i = elemsData.iterator(); i.hasNext();) { - JSONObject elemData = (JSONObject)i.next(); - elems.add(catalog().proxy(elemData, etype)); - } - } - catch(Exception e){ - throw new RuntimeException("Failed to fetch json data ", e); - } - return (E)elems; - } - } - - /* - */ - public default boolean same(Element theElem) { - return this.catalog().same(theElem.catalog()) && - this.id().equals(theElem.id()); - } - } - - /* - * Base class for all collections of elements. - */ - public static class Elements<T extends Element> - extends LinkedList<T> { - - public String toString() { - StringBuilder sb = new StringBuilder("["); - for (Element el: this) { - sb.append(el.selfClass().getSimpleName()) - .append("(") - .append(el.data()) - .append("),"); - } - sb.append("]"); - return sb.toString(); - } - } - - /* - * We need this contraption in order to store a mix of Folders and CatalogItem - * instances (Elements in self is not good because it is defined around a - * type variable so we cannot use reflection to determine the type at runtime - * - generics are resolved compile time) - */ - public static class Mixels extends Elements<Element> { - } - - /* - */ - public static interface Item<T extends Item<T>> extends Element<T> { - - public String name(); - - public String description(); - - /* catalog item native identifier */ - public String itemId(); - - /* similar to @ItemAction#withModels - */ - default public Future<Templates> models() { - Templates t = elements("models", Templates.class); - if (t != null) - return Futures.succeededFuture(t); - else - return Futures.advance(catalog().item(itemId()) - .withModels() - .execute(), - item -> (Templates)item.elements("models", Templates.class)); - } - - /* similar to @ItemAction#withAnnotations - */ - default public Future<Annotations> annotations() { - Annotations a = elements("annotations", Annotations.class); - if (a != null) - return Futures.succeededFuture(a); - else - return Futures.advance(catalog().item(itemId()) - .withAnnotations() - .execute(), - item -> (Annotations)item.elements("annotations", Annotations.class)); - } - } - - /* - * Collection of catalog items. - */ - public static class Items extends Elements<Item> { - } - - /* - */ - public static interface Folder extends Element<Folder> { - - public String name(); - - public String description(); - - public String itemId(); - - /* the namespace is immutable */ - public default String namespace() { - return catalog().namespace(); - } - - /* - */ - default public Future<Items> items() { - Items i = elements("items", Items.class); - if (i != null) - return Futures.succeededFuture(i); - else - return Futures.advance(catalog().folder(itemId()) - .withItems() - .execute(), - folder -> (Items)folder.elements("items", Items.class)); - } - - /* - */ - default public Future<Folders> parts() { - Folders f = elements("parts", Folders.class); - if (f != null) - return Futures.succeededFuture(f); - else - return Futures.advance(catalog().folder(itemId()) - .withParts() - .execute(), - folder -> (Folders)folder.elements("parts", Folders.class)); - } - - /* - */ - public Future<Folders> partof(); - - } - - - public static class Folders extends Elements<Folder> { - } - - //no predefined properties here - public static interface Annotation extends Element<Annotation> { - - public default String namespace() { - return catalog().namespace(); + URI getUri(); + + <T> T proxy(JSONObject theData, Class<T> theType); + + + /* Base class for all Catalog objects. */ + interface Element<T extends Element<T>> { + + default Class<T> selfClass() { + return (Class<T>)getClass().getInterfaces()[0]; + } + + Catalog catalog(); + + String id(); + + /** + * Direct access to the underlying JSON object. + * Warning: Modifications to the JSON object are reflected in the Element. + */ + JSONObject data(); + + /* Allows for typed deep exploration of the backing JSON data structure + * @arg theName name of a JSON entry ; It must map another JSONObject. + * @arg theType the expected wrapping catalog artifact type + * @return the JSON entry wrapped in the specified type + */ + default <E extends Element<E>> E element(String theName, Class<E> theType) { + JSONObject elemData = data().optJSONObject(theName); + if (elemData == null) { + return null; + } + else { + return catalog().proxy(elemData, theType); + } + } + + /* Similar to {@link #element(String,Class)} but for collection wrapping. */ + default <E extends Elements> E elements(String theName, Class<E> theType) { + JSONArray elemsData = data().optJSONArray(theName); + if (elemsData == null) { + return null; + } + else { + Class etype = Proxies.typeArgument(theType); + Elements elems; + try { + elems = theType.newInstance(); + } + catch (ReflectiveOperationException rox) { + throw new RuntimeException("Failed to instantiate " + theType, rox); + } + + try{ + for (Iterator i = elemsData.iterator(); i.hasNext();) { + JSONObject elemData = (JSONObject)i.next(); + elems.add(catalog().proxy(elemData, etype)); + } + } + catch(Exception e){ + throw new RuntimeException("Failed to fetch json data ", e); + } + return (E)elems; + } + } + } + + /* Base class for all collections of elements. */ + class Elements<T extends Element> + extends LinkedList<T> { + @Override + public String toString() { + StringBuilder sb = new StringBuilder("["); + for (Element el: this) { + sb.append(el.selfClass().getSimpleName()) + .append("(") + .append(el.data()) + .append("),"); + } + sb.append("]"); + return sb.toString(); + } + } + + /* + * We need this contraption in order to store a mix of Folders and CatalogItem + * instances (Elements in self is not good because it is defined around a + * type variable so we cannot use reflection to determine the type at runtime + * - generics are resolved compile time) + */ + class Mixels extends Elements<Element> {} + + interface Item<T extends Item<T>> extends Element<T> { + String name(); + String description(); + } + + /* + * Collection of catalog items. + */ + class Items extends Elements<Item> {} + + interface Folder extends Element<Folder> { + + String name(); + + String description(); + + String itemId(); + + default Future<Items> items() { + Items i = elements("items", Items.class); + if (i != null) { + return Futures.succeededFuture(i); + } + else { + return Futures.advance(catalog().folder(itemId()) + .withItems() + .execute(), + folder -> folder.elements("items", Items.class)); + } + } } - } - public static class Annotations extends Elements<Annotation> { + class Folders extends Elements<Folder> {} + + //no predefined properties here + interface Annotation extends Element<Annotation> {} + + class Annotations extends Elements<Annotation> { } - /** - * A TOSCA teamplate. - * When a deep loading method is used to obtain a Template its collection - * of inputs and nodes will be immediately available (and 'cached' within - * the backing JSON object). It can be retrieved through a call to - * {@link Element#elements(String,Class)} as in: - * elements("inputs", Inputs.class) - * or - * elements("nodes", Nodes.class) - * - * The same result will be obtained through one of the methods of the - * navigation interface, {@link #inputs()} or {@link #nodes()}; in this case - * the result does not become part of the backing JSONObject. - */ - public static interface Template extends Element<Template> { - - public String name(); - - public String version(); - - public String description(); - - } - - /** - * Collection of {@link Catalog.Template template} instances. - */ - public static class Templates extends Elements<Template> { - } - - - /** - * A TOSCA type declaration. - */ - public interface Type extends Element<Type> { - - public String name(); - - /** - * Allows navigation to the parent {@link Catalog.Type type}, if any. - */ - public Future<Type> derivedfrom(); - - } - - /** - * Collection of {@link Catalog.Type type} instances. - */ - public static class Types extends Elements<Type> { - } - - - public static interface TemplateAction extends Action<Template> { - - public TemplateAction withInputs(); - - public TemplateAction withOutputs(); - - public TemplateAction withNodes(); - - public TemplateAction withNodeProperties(); - - public TemplateAction withNodeRequirements(); - - public TemplateAction withNodePropertiesAssignments(); - - public TemplateAction withNodeCapabilities(); - - public TemplateAction withNodeCapabilityProperties(); - - public TemplateAction withNodeCapabilityPropertyAssignments(); - - public TemplateAction withPolicies(); - - public TemplateAction withPolicyProperties(); - - public TemplateAction withPolicyPropertiesAssignments(); - - @Override - public Future<Template> execute(); - - } - - /* - */ - public static interface TypeAction extends Action<Type> { - - public TypeAction withHierarchy(); - - public TypeAction withRequirements(); - - public TypeAction withCapabilities(); - - @Override - public Future<Type> execute(); - - } - - /* - */ - public static interface FolderAction extends Action<Folder> { - - public FolderAction withAnnotations(); - - public FolderAction withAnnotations(String theSelector); - - public FolderAction withItems(); - - public FolderAction withItemAnnotations(); - - public FolderAction withItemAnnotations(String theSelector); + /** + * A TOSCA teamplate. + * When a deep loading method is used to obtain a Template its collection + * of inputs and nodes will be immediately available (and 'cached' within + * the backing JSON object). It can be retrieved through a call to + * {@link Element#elements(String,Class)} as in: + * elements("inputs", Inputs.class) + * or + * elements("nodes", Nodes.class) + * + * The same result will be obtained through one of the methods of the + * navigation interface. in this case + * the result does not become part of the backing JSONObject. + */ + interface Template extends Element<Template> { + String name(); + + String version(); + + String description(); + } + + /** + * Collection of {@link Catalog.Template template} instances. + */ + class Templates extends Elements<Template> { + } + + + /** + * A TOSCA type declaration. + */ + interface Type extends Element<Type> { + String name(); + } + + /** + * Collection of {@link Catalog.Type type} instances. + */ + class Types extends Elements<Type> { + } + - public FolderAction withItemModels(); + interface TemplateAction extends Action<Template> { - public FolderAction withParts(); - - public FolderAction withPartAnnotations(); + TemplateAction withInputs(); - public FolderAction withPartAnnotations(String theSelector); + TemplateAction withOutputs(); - @Override - public Future<Folder> execute(); - } - - /* - */ - public static interface ItemAction<T extends Item> extends Action<T> { + TemplateAction withNodes(); - public ItemAction<T> withModels(); + TemplateAction withNodeProperties(); - public ItemAction<T> withAnnotations(); - - @Override - public Future<T> execute(); + TemplateAction withNodeRequirements(); - } + TemplateAction withNodePropertiesAssignments(); - /** - */ - public abstract Future<Folders> roots(); + TemplateAction withNodeCapabilities(); - /** - */ - public abstract Future<Folders> rootsByLabel(String theLabel); + TemplateAction withNodeCapabilityProperties(); - /** - */ - public abstract Future<Mixels> lookup(JSONObject theSelector); - - public abstract Future<Mixels> lookup(String theAnnotation, JSONObject theSelector); - - /** - */ - public abstract FolderAction folder(String theFolderId); + TemplateAction withNodeCapabilityPropertyAssignments(); - /** - */ - public abstract <T extends Item> ItemAction<T> item(String theItemId); + TemplateAction withPolicies(); + + TemplateAction withPolicyProperties(); + + TemplateAction withPolicyPropertiesAssignments(); + + @Override + Future<Template> execute(); + } + + interface TypeAction extends Action<Type> { + + TypeAction withHierarchy(); + + TypeAction withRequirements(); + + TypeAction withCapabilities(); + + @Override + Future<Type> execute(); + } + + interface FolderAction extends Action<Folder> { + + FolderAction withItems(); + + FolderAction withItemAnnotations(); + + FolderAction withItemModels(); + + FolderAction withParts(); + + FolderAction withPartAnnotations(); + + @Override + Future<Folder> execute(); + } + + interface ItemAction<T extends Item> extends Action<T> { + + ItemAction<T> withModels(); + + @Override + Future<T> execute(); + + } - /** - */ - public abstract TemplateAction template(String theTemplateId); + Future<Folders> rootsByLabel(String theLabel); - /** - */ - public abstract TypeAction type(String theNamespace, String theTypeName); + FolderAction folder(String theFolderId); + <T extends Item> ItemAction<T> item(String theItemId); + TemplateAction template(String theTemplateId); + TypeAction type(String theNamespace, String theTypeName); } diff --git a/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCCatalog.java b/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCCatalog.java index e08f3a6..dfbaeaa 100644 --- a/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCCatalog.java +++ b/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCCatalog.java @@ -22,6 +22,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; +@SuppressWarnings("ALL") public class ASDCCatalog implements Catalog { private @@ -87,10 +88,10 @@ public class ASDCCatalog implements Catalog { private String[] folderFields = new String[] {ID, ITEM_ID, NAME}; private ProxyBuilder proxies; - private Map<Target, JXPathContext> contexts = new HashMap<Target, JXPathContext>(); + private Map<Target, JXPathContext> contexts = new HashMap<>(); // resource and its catalog - private Map<UUID, org.onap.sdc.dcae.checker.Catalog> catalogs = new HashMap<UUID, org.onap.sdc.dcae.checker.Catalog>(); + private Map<UUID, org.onap.sdc.dcae.checker.Catalog> catalogs = new HashMap<>(); public ASDCCatalog(URI theURI) { @@ -171,7 +172,6 @@ public class ASDCCatalog implements Catalog { return Futures.succeededFuture(roots); } - /** */ public Future<Mixels> lookup(JSONObject theSelector) { return Futures.succeededFuture(new Mixels()); } @@ -180,66 +180,48 @@ public class ASDCCatalog implements Catalog { return Futures.succeededFuture(new Mixels()); } - /** */ public ItemAction item(String theItemId) { return new ResourceAction(UUID.fromString(theItemId)); } - /** */ - public FolderAction folder(String theFolderId) { - return new FolderAction(theFolderId); - } - - public TemplateAction template(String theId) { - return new TemplateAction(theId); + public CatalogFolderAction folder(String theFolderId) { + return new CatalogFolderAction(theFolderId); } - public TypeAction type(String theItemId, String theName) { - return new TypeAction(UUID.fromString(theItemId), theName); + public CatalogTemplateAction template(String theId) { + return new CatalogTemplateAction(theId); } - protected static String resolveTargetName(Target theTarget) { - return (String) ((Map) ((Map) theTarget.getTarget()).get("metadata")).get("template_name"); + public CatalogTypeAction type(String theItemId, String theName) { + return new CatalogTypeAction(UUID.fromString(theItemId), theName); } - protected Object resolve(Target theTarget, String thePath) { + private Object resolve(Target theTarget, String thePath) { try { return contexts.get(theTarget).getValue(thePath); } catch (JXPathNotFoundException pnfx) { - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "JXPathNotFoundException {}", pnfx); + debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), JXPATH_NOT_FOUND_EXCEPTION, pnfx); return null; } } // covers common TOSCA pattern of single entry maps - public Map.Entry<String, Map> toEntry(Object theValue) { + private Map.Entry<String, Map> toEntry(Object theValue) { return (Map.Entry<String, Map>) ((Map) theValue).entrySet().iterator().next(); } - protected Map selectEntries(Map theOriginal, String... theKeys) { + private Map selectEntries(Map theOriginal, String... theKeys) { Arrays.sort(theKeys); - Map selection = ((Set<Map.Entry>) theOriginal.entrySet()).stream() + return ((Set<Map.Entry>) theOriginal.entrySet()).stream() .filter(e -> Arrays.binarySearch(theKeys, e.getKey().toString()) >= 0) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); - return selection; } - protected Map evictEntries(Map theOriginal, String... theKeys) { + private Map evictEntries(Map theOriginal, String... theKeys) { Arrays.sort(theKeys); - Map selection = ((Set<Map.Entry>) theOriginal.entrySet()).stream() + return ((Set<Map.Entry>) theOriginal.entrySet()).stream() .filter(e -> Arrays.binarySearch(theKeys, e.getKey().toString()) < 0) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); - return selection; - } - - protected MapBuilder renderEntry(Map.Entry theEntry, String... theKeys) { - MapBuilder out = new MapBuilder(); - out.put(NAME, theEntry.getKey()); - - for (String key : theKeys) { - out.put(key, ((Map) theEntry.getValue()).get(key)); - } - return out; } protected <T> Stream<T> stream(Iterator<T> theSource) { @@ -277,18 +259,17 @@ public class ASDCCatalog implements Catalog { } private static void dumpTargets(String theDirName, Collection<Target> theTargets) { - try { - File targetDir = new File(theDirName); - if (!targetDir.exists() && !targetDir.mkdirs()) { - throw new IllegalStateException("Couldn't create dir: " + theDirName); - } - for (Target t : theTargets) { - FileWriter dump = new FileWriter(new File(theDirName, t.getName())); + File targetDir = new File(theDirName); + if (!targetDir.exists() && !targetDir.mkdirs()) { + throw new IllegalStateException("Couldn't create dir: " + theDirName); + } + for (Target t : theTargets) { + try (FileWriter dump = new FileWriter(new File(theDirName, t.getName()))) { IOUtils.copy(t.open(), dump); dump.close(); + } catch (IOException e) { + debugLogger.log(LogLevel.DEBUG, "ASDCCatalog", "IOException {}", e); } - } catch (IOException iox) { - debugLogger.log(LogLevel.DEBUG,"ASDCCatalog", "IOException {}", iox); } } @@ -365,50 +346,50 @@ public class ASDCCatalog implements Catalog { } } - public class FolderAction implements Catalog.FolderAction { + public class CatalogFolderAction implements Catalog.FolderAction { private boolean doItemModels; private String folderName; // use the id/UUID of the folder ?? - private FolderAction(String theFolderName) { + private CatalogFolderAction(String theFolderName) { this.folderName = theFolderName; } - public FolderAction withAnnotations() { + public CatalogFolderAction withAnnotations() { return this; } - public FolderAction withAnnotations(String theSelector) { + public CatalogFolderAction withAnnotations(String theSelector) { return this; } - public FolderAction withItems() { + public CatalogFolderAction withItems() { return this; } - public FolderAction withItemAnnotations() { + public CatalogFolderAction withItemAnnotations() { return this; } - public FolderAction withItemAnnotations(String theSelector) { + public CatalogFolderAction withItemAnnotations(String theSelector) { return this; } - public FolderAction withItemModels() { + public CatalogFolderAction withItemModels() { doItemModels = true; return this; } - public FolderAction withParts() { + public CatalogFolderAction withParts() { return this; } - public FolderAction withPartAnnotations() { + public CatalogFolderAction withPartAnnotations() { return this; } - public FolderAction withPartAnnotations(String theSelector) { + public CatalogFolderAction withPartAnnotations(String theSelector) { return this; } @@ -425,7 +406,7 @@ public class ASDCCatalog implements Catalog { return Futures.advance(asdc.getResources(JSONArray.class, "DCAE Component", this.folderName), resourcesData -> { - Actions.CompoundAction<Resource> itemsAction = new Actions.BasicCompoundAction<Resource>(); + Actions.CompoundAction<Resource> itemsAction = new Actions.BasicCompoundAction<>(); for (int i = 0; i < resourcesData.length(); i++) { JSONObject resource = resourcesData.getJSONObject(i); @@ -453,7 +434,7 @@ public class ASDCCatalog implements Catalog { }, resourcesError -> new RuntimeException("Failed to retrieve resources", resourcesError)); } - public Collection<Resource> filterLatestVersion(Collection<Resource> items) throws IllegalArgumentException { + public Collection<Resource> filterLatestVersion(Collection<Resource> items) { if (items == null) { throw new IllegalArgumentException("null is not acceptable as a list of items"); } @@ -475,7 +456,7 @@ public class ASDCCatalog implements Catalog { } /** */ - public class TemplateAction implements Catalog.TemplateAction { + public class CatalogTemplateAction implements Catalog.TemplateAction { private String artifactId; private Target target; @@ -485,32 +466,28 @@ public class ASDCCatalog implements Catalog { private boolean doNodes, doNodeProperties, doNodePropertiesAssignments, doNodeRequirements, doNodeCapabilities, doNodeCapabilityProperties, doNodeCapabilityPropertyAssignments; - protected TemplateAction(Target theTarget) { - this.target = theTarget; - } - /* * expected to be the relative url provided by asdc for the template * artifact */ - protected TemplateAction(String theArtifactId) { + CatalogTemplateAction(String theArtifactId) { this.artifactId = theArtifactId; } - public TemplateAction withInputs() { + public CatalogTemplateAction withInputs() { return this; } - public TemplateAction withOutputs() { + public CatalogTemplateAction withOutputs() { return this; } - public TemplateAction withNodes() { + public CatalogTemplateAction withNodes() { this.doNodes = true; return this; } - protected TemplateAction doNodes() { + CatalogTemplateAction doNodes() { if (!this.doNodes) { return this; } @@ -531,12 +508,12 @@ public class ASDCCatalog implements Catalog { } // pre-requisite: a call to 'withNodes' - public TemplateAction withNodeProperties() { + public CatalogTemplateAction withNodeProperties() { this.doNodeProperties = true; return this; } - protected TemplateAction doNodeProperties() { + protected CatalogTemplateAction doNodeProperties() { if (!this.doNodeProperties) { return this; } @@ -558,12 +535,12 @@ public class ASDCCatalog implements Catalog { } // pre-requisite: a call to 'withNodesProperties' - public TemplateAction withNodePropertiesAssignments() { + public CatalogTemplateAction withNodePropertiesAssignments() { this.doNodePropertiesAssignments = true; return this; } - protected TemplateAction doNodePropertiesAssignments() { + CatalogTemplateAction doNodePropertiesAssignments() { if (!this.doNodePropertiesAssignments) { return this; } @@ -573,8 +550,8 @@ public class ASDCCatalog implements Catalog { return this; } - nodes.entrySet().stream().forEach(node -> { - List nodeProps = null; + nodes.entrySet().forEach(node -> { + List nodeProps; try { nodeProps = (List) ctx.getValue(NODES_NAME + ((Map.Entry) node).getKey() + PROPERTIES); } catch (JXPathNotFoundException pnfx) { @@ -582,7 +559,7 @@ public class ASDCCatalog implements Catalog { return; } - nodeProps.stream().forEach(prop -> { + nodeProps.forEach(prop -> { // pick from String propPath = TOPOLOGY_TEMPLATE_NODE_TEMPLATES1 + ((Map.Entry) node).getKey() + "/properties/" + ((Map) prop).get(NAME); @@ -602,7 +579,7 @@ public class ASDCCatalog implements Catalog { return this; } - protected Map renderRequirementDefinition(Map.Entry theReq) { + Map renderRequirementDefinition(Map.Entry theReq) { Map def = (Map) theReq.getValue(); return new MapBuilder().put(NAME, theReq.getKey()) // capability must be present @@ -613,7 +590,7 @@ public class ASDCCatalog implements Catalog { } // TODO: see how this comes out of neo and match it - protected Map renderRequirementAssignment(Map.Entry theReq) { + Map renderRequirementAssignment(Map.Entry theReq) { Map def = (Map) theReq.getValue(); return new MapBuilder().put(NAME, theReq.getKey()) // capability must be present @@ -628,12 +605,12 @@ public class ASDCCatalog implements Catalog { .putAll(evictEntries(def, CAPABILITY)).build(); } - public TemplateAction withNodeRequirements() { + public CatalogTemplateAction withNodeRequirements() { this.doNodeRequirements = true; return this; } - TemplateAction doNodeRequirements() { + CatalogTemplateAction doNodeRequirements() { if (!this.doNodeRequirements) { return this; } @@ -647,7 +624,7 @@ public class ASDCCatalog implements Catalog { } // type - nodes.entrySet().stream() + nodes.entrySet() .forEach( node -> ctx .setValue( @@ -666,13 +643,13 @@ public class ASDCCatalog implements Catalog { .collect(Collectors.toList()))); // merge assignments on top of definitions - nodes.entrySet().stream().forEach(node -> { + nodes.entrySet().forEach(node -> { List nodeReqsAssigns = (List) resolve(this.target, TOPOLOGY_TEMPLATE_NODE_TEMPLATES1 + ((Map.Entry) node).getKey() + "/requirements"); if (nodeReqsAssigns == null) { return; } - nodeReqsAssigns.stream().forEach(req -> { + nodeReqsAssigns.forEach(req -> { Map.Entry reqAssign = toEntry(req); catalog.mergeDefinitions((Map) ctx.getValue(NODES_NAME + ((Map.Entry) node).getKey() + "']/requirements[name='" + reqAssign.getKey() + "']"), @@ -683,12 +660,12 @@ public class ASDCCatalog implements Catalog { return this; } - public TemplateAction withNodeCapabilities() { + public CatalogTemplateAction withNodeCapabilities() { this.doNodeCapabilities = true; return this; } - protected Map renderCapabilityDefinition(Map.Entry theCap) { + Map renderCapabilityDefinition(Map.Entry theCap) { Map def = (Map) theCap.getValue(); return new MapBuilder().put(NAME, theCap.getKey()) .put("type", @@ -697,7 +674,7 @@ public class ASDCCatalog implements Catalog { .putAll(evictEntries(def, "properties", "type")).build(); } - TemplateAction doNodeCapabilities() { + CatalogTemplateAction doNodeCapabilities() { if (!this.doNodeCapabilities) { return this; } @@ -718,18 +695,18 @@ public class ASDCCatalog implements Catalog { stream(catalog.facets(Construct.Node, Facet.capabilities, ((Map) ((Map.Entry) node).getValue()).get("type").toString())) - .map((Map.Entry capEntry) -> renderCapabilityDefinition(capEntry)) + .map(this::renderCapabilityDefinition) .collect(Collectors.toList()))); return this; } - public TemplateAction withNodeCapabilityProperties() { + public CatalogTemplateAction withNodeCapabilityProperties() { this.doNodeCapabilityProperties = true; return this; } - TemplateAction doNodeCapabilityProperties() { + CatalogTemplateAction doNodeCapabilityProperties() { if (!this.doNodeCapabilityProperties) { return this; @@ -742,7 +719,7 @@ public class ASDCCatalog implements Catalog { // pick up all the properties from the capability type hierarchy // definition - nodes.entrySet().stream().forEach(node -> { + nodes.entrySet().forEach(node -> { List nodeCapabilities = (List) ctx .getValue(NODES_NAME + ((Map.Entry) node).getKey() + CAPABILITIES); if (nodeCapabilities == null) { @@ -750,7 +727,7 @@ public class ASDCCatalog implements Catalog { } // collect properties from the capability type hierarchy - nodeCapabilities.stream().forEach(capability -> { + nodeCapabilities.forEach(capability -> { List capabilityProperties = StreamSupport .stream(Spliterators.spliteratorUnknownSize( catalog.facets(Construct.Capability, Facet.properties, @@ -781,7 +758,7 @@ public class ASDCCatalog implements Catalog { return; } - properties.entrySet().stream().forEach(property -> { + properties.entrySet().forEach(property -> { String propertyLoc = NODES_NAME + ((Map.Entry) node).getKey() + CAPABILITIES_NAME + ((Map) capability).get(NAME) + PROPERTIES_NAME + ((Map.Entry) property).getKey() + "']"; @@ -794,12 +771,12 @@ public class ASDCCatalog implements Catalog { return this; } - public TemplateAction withNodeCapabilityPropertyAssignments() { + public CatalogTemplateAction withNodeCapabilityPropertyAssignments() { this.doNodeCapabilityPropertyAssignments = true; return this; } - TemplateAction doNodeCapabilityPropertyAssignments() { + CatalogTemplateAction doNodeCapabilityPropertyAssignments() { if (!this.doNodeCapabilityPropertyAssignments) { return this; } @@ -818,14 +795,14 @@ public class ASDCCatalog implements Catalog { return this; } - nodes.stream().forEach(node -> { + nodes.forEach(node -> { List capabilities = (List) ctx.getValue(NODES_NAME + ((Map) node).get(NAME) + CAPABILITIES); if (capabilities == null) { return; } - capabilities.stream().forEach(capability -> { - List properties = null; + capabilities.forEach(capability -> { + List properties; try { properties = (List) ctx.getValue(NODES_NAME + ((Map) node).get(NAME) + CAPABILITIES_NAME + ((Map) capability).get(NAME) + PROPERTIES); @@ -834,7 +811,7 @@ public class ASDCCatalog implements Catalog { return; } - properties.stream().forEach(property -> { + properties.forEach(property -> { String location = NODES_NAME + ((Map) node).get(NAME) + CAPABILITIES_NAME + ((Map) capability).get(NAME) + PROPERTIES_NAME + ((Map) property).get(NAME) + "']/assignment"; @@ -859,15 +836,15 @@ public class ASDCCatalog implements Catalog { return this; } - public TemplateAction withPolicies() { + public CatalogTemplateAction withPolicies() { return this; } - public TemplateAction withPolicyProperties() { + public CatalogTemplateAction withPolicyProperties() { return this; } - public TemplateAction withPolicyPropertiesAssignments() { + public CatalogTemplateAction withPolicyPropertiesAssignments() { return this; } @@ -913,7 +890,7 @@ public class ASDCCatalog implements Catalog { this.catalog = checker.catalog(); ASDCCatalog.this.catalogs.put(resourceId, this.catalog); // we should only be doing this if we discovered an update - // (by checking timestampts). Actually, we should + // (by checking timestamps). Actually, we should // only do the artifact fetching if we detect an update ASDCCatalog.this.contexts.put(template, JXPathContext.newContext(template.getTarget())); } catch (Exception x) { @@ -924,7 +901,7 @@ public class ASDCCatalog implements Catalog { this.doNodes().doNodeProperties().doNodePropertiesAssignments().doNodeRequirements().doNodeCapabilities() .doNodeCapabilityProperties().doNodeCapabilityPropertyAssignments(); - JSONObject pack = new JSONObject((Map) ctx.getContextBean()).put(NAME, this.target.getName().toString()) + JSONObject pack = new JSONObject((Map) ctx.getContextBean()).put(NAME, this.target.getName()) .put(ID, this.target.getLocation().toString()) .put(ITEM_ID, this.target.getLocation().toString()); debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), pack.toString(2)); @@ -933,7 +910,7 @@ public class ASDCCatalog implements Catalog { } } - public class TypeAction implements Catalog.TypeAction { + public class CatalogTypeAction implements Catalog.TypeAction { private String name; private UUID resourceId; @@ -941,17 +918,17 @@ public class ASDCCatalog implements Catalog { private boolean doHierarchy = false, doRequirements = false, doCapabilities = false; - private TypeAction(UUID theResourceId, /* Construct theConstruct, */ String theName) { + private CatalogTypeAction(UUID theResourceId, /* Construct theConstruct, */ String theName) { this.resourceId = theResourceId; this.name = theName; } - public TypeAction withHierarchy() { + public CatalogTypeAction withHierarchy() { this.doHierarchy = true; return this; } - TypeAction doHierarchy(org.onap.sdc.dcae.checker.Catalog theCatalog) { + CatalogTypeAction doHierarchy(org.onap.sdc.dcae.checker.Catalog theCatalog) { if (!this.doHierarchy) { return this; } @@ -968,12 +945,12 @@ public class ASDCCatalog implements Catalog { return this; } - public TypeAction withRequirements() { + public CatalogTypeAction withRequirements() { this.doRequirements = true; return this; } - TypeAction doRequirements(org.onap.sdc.dcae.checker.Catalog theCatalog) { + CatalogTypeAction doRequirements(org.onap.sdc.dcae.checker.Catalog theCatalog) { if (!this.doRequirements) { return this; } @@ -991,7 +968,7 @@ public class ASDCCatalog implements Catalog { // (within a node type) .put(ID, getCatalog(resourceId).hasType(Construct.Capability, capability) - ? (resourceId + "/" + capability) : capability.toString()) + ? (resourceId + "/" + capability) : capability) .build()) .put("node", new MapBuilder().putOpt(NAME, node).putOpt(ID, node == null ? null : (resourceId + "/" + node)).buildOpt()) @@ -1004,12 +981,12 @@ public class ASDCCatalog implements Catalog { return this; } - public TypeAction withCapabilities() { + public CatalogTypeAction withCapabilities() { this.doCapabilities = true; return this; } - TypeAction doCapabilities(org.onap.sdc.dcae.checker.Catalog theCatalog) { + CatalogTypeAction doCapabilities(org.onap.sdc.dcae.checker.Catalog theCatalog) { if (!this.doCapabilities) { return this; } @@ -1065,7 +1042,7 @@ public class ASDCCatalog implements Catalog { } } - public static interface Resource extends Catalog.Item<Resource> { + public interface Resource extends Catalog.Item<Resource> { @Override @Proxy.DataMap(map = "uuid") @@ -1091,22 +1068,22 @@ public class ASDCCatalog implements Catalog { public static class Resources extends Elements<Resource> { } - public static interface Artifact extends Catalog.Element<Artifact> { + public interface Artifact extends Catalog.Element<Artifact> { @Proxy.DataMap(map = ARTIFACT_NAME) - public String name(); + String name(); @Proxy.DataMap(map = "artifactType") - public String type(); + String type(); @Proxy.DataMap(map = "artifactDescription") - public String description(); + String description(); @Proxy.DataMap(map = "artifactUUID") - public UUID uuid(); + UUID uuid(); @Proxy.DataMap(map = "artifactVersion") - public int version(); + int version(); } @@ -1150,7 +1127,7 @@ public class ASDCCatalog implements Catalog { return null; } - ASDCTarget target = null; + ASDCTarget target; if (this.catalog != null) { // this is the caching!! target = (ASDCTarget) this.catalog.getTarget(ASDCCatalog.this.getArtifactURI(targetArtifact)); @@ -1210,16 +1187,20 @@ public class ASDCCatalog implements Catalog { Resources items = f.elements(ITEMS, Resources.class); if (items != null) { for (Resource item : items) { - debugLogger.log(LogLevel.DEBUG, ASDCCatalog.class.getName(), "\titem: {} : {}",item.name(), item.data()); - Templates templates = item.elements(MODELS, Templates.class); - if (templates != null) { - for (Template t : templates) { - Template ft = catalog.template(t.id()).withNodes().withNodeProperties() - .withNodePropertiesAssignments().execute().waitForResult(); - - debugLogger.log(LogLevel.DEBUG, ASDCCatalog.class.getName(), "template data: {}", ft.data()); - } - } + executeItemsNodePropertiesAssignments(catalog, item); + } + } + } + + private static void executeItemsNodePropertiesAssignments(ASDCCatalog catalog, Resource item) throws Exception { + debugLogger.log(LogLevel.DEBUG, ASDCCatalog.class.getName(), "\titem: {} : {}",item.name(), item.data()); + Templates templates = item.elements(MODELS, Templates.class); + if (templates != null) { + for (Template t : templates) { + Template ft = catalog.template(t.id()).withNodes().withNodeProperties() + .withNodePropertiesAssignments().execute().waitForResult(); + + debugLogger.log(LogLevel.DEBUG, ASDCCatalog.class.getName(), "template data: {}", ft.data()); } } } diff --git a/dcaedt_catalog/api/src/test/java/org/onap/sdc/dcae/catalog/ASDCCatalogTest.java b/dcaedt_catalog/api/src/test/java/org/onap/sdc/dcae/catalog/ASDCCatalogTest.java index fcd92f0..360b76d 100644 --- a/dcaedt_catalog/api/src/test/java/org/onap/sdc/dcae/catalog/ASDCCatalogTest.java +++ b/dcaedt_catalog/api/src/test/java/org/onap/sdc/dcae/catalog/ASDCCatalogTest.java @@ -12,7 +12,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog; -import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog.FolderAction; +import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog.CatalogFolderAction; import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog.Resource; import static org.mockito.Mockito.*; @@ -23,17 +23,17 @@ public class ASDCCatalogTest { @Rule public ExpectedException thrown = ExpectedException.none(); - private static FolderAction getTarget() { + private static CatalogFolderAction getTarget() { ASDCCatalog catalog = mock(ASDCCatalog.class); when(catalog.folder("test")).thenCallRealMethod(); - FolderAction target = catalog.folder("test"); + CatalogFolderAction target = catalog.folder("test"); return target; } @Test public void filterLatestVersion_null_throwIllegalArgumentException() { // arrange - FolderAction target = getTarget(); + CatalogFolderAction target = getTarget(); // assert thrown.expect(IllegalArgumentException.class); // act @@ -43,7 +43,7 @@ public class ASDCCatalogTest { @Test public void filterLatestVersion_emptyItemsList_emptyItemsList() throws URISyntaxException { // arrange - FolderAction target = getTarget(); + CatalogFolderAction target = getTarget(); // act Collection<Resource> result = target.filterLatestVersion(new ArrayList<>()); // assert @@ -53,7 +53,7 @@ public class ASDCCatalogTest { @Test public void filterLatestVersion_itemWithTwoVersions_itemWithLatestVersion() { // arrange - FolderAction target = getTarget(); + CatalogFolderAction target = getTarget(); UUID invariantUUID = UUID.randomUUID(); Resource r1v1 = mock(Resource.class); @@ -72,7 +72,7 @@ public class ASDCCatalogTest { @Test public void filterLatestVersion_2distinctItems_2distinctItems() { // arrange - FolderAction target = getTarget(); + CatalogFolderAction target = getTarget(); Resource r1 = mock(Resource.class); Resource r2 = mock(Resource.class); |