+ /**
+ * Add the supplied Node Template to the Service, provided that it is a valid Resource or Widget. If the Node
+ * Template is a Resource type, this is also recorded in the supplied nodesById Map.
+ *
+ * @param nodesById a map of Resource node type names, keyed by UUID
+ * @param service the Service to which the Node Template should be added
+ * @param nodeTemplate the Node Template to add (only if this is a Resource or Widget type)
+ */
+ private void addNodeToService(Map<String, String> nodesById, Service service, NodeTemplate nodeTemplate) {
+ String nodeTypeName = normaliseNodeTypeName(nodeTemplate);
+ Model model = Model.getModelFor(nodeTypeName);
+ if (model != null) {
+ if (nodeTemplate.getMetaData() != null) {
+ model.populateModelIdentificationInformation(nodeTemplate.getMetaData().getAllProperties());
+ }
+
+ if (model instanceof Resource) {
+ nodesById.put(model.getModelNameVersionId(), nodeTypeName);
+ service.addResource((Resource) model);
+ } else {
+ service.addWidget((Widget) model);
+ }
+ }
+ }
+