Skip to content

Commit f746b00

Browse files
authored
fix handling of properties of artifactTemplates (#181)
1 parent 6f0388a commit f746b00

File tree

1 file changed

+66
-62
lines changed
  • org.opentosca.bus/org.opentosca.bus.management.service/src/main/java/org/opentosca/bus/management/service/impl/util

1 file changed

+66
-62
lines changed

org.opentosca.bus/org.opentosca.bus.management.service/src/main/java/org/opentosca/bus/management/service/impl/util/Util.java

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,70 +17,74 @@
1717

1818
public class Util {
1919

20-
private final static Logger LOG = LoggerFactory.getLogger(Util.class);
20+
private final static Logger LOG = LoggerFactory.getLogger(Util.class);
2121

22-
/**
23-
* Determine the ServiceTemplateInstanceId long from the ServiceInstanceId QName.
24-
*
25-
* @return the ServiceTemplateInstanceId if the retrieval is successful, <code>Long.MIN_VALUE</code> otherwise
26-
*/
27-
public static long determineServiceTemplateInstanceId(final URI serviceInstanceID) {
28-
if (Objects.nonNull(serviceInstanceID)) {
29-
try {
30-
if (serviceInstanceID.toString().contains("/")) {
31-
return Long.parseLong(StringUtils.substringAfterLast(serviceInstanceID.toString(), "/"));
32-
} else {
33-
return Long.parseLong(serviceInstanceID.toString());
34-
}
35-
} catch (final NumberFormatException e) {
36-
LOG.error("Unable to parse ServiceTemplateInstance ID out of serviceInstanceID: {}", serviceInstanceID);
37-
}
38-
} else {
39-
LOG.error("Unable to parse ServiceTemplateInstance ID out of serviceInstanceID because it is null!");
40-
}
41-
return Long.MIN_VALUE;
42-
}
22+
/**
23+
* Determine the ServiceTemplateInstanceId long from the ServiceInstanceId
24+
* QName.
25+
*
26+
* @return the ServiceTemplateInstanceId if the retrieval is successful,
27+
* <code>Long.MIN_VALUE</code> otherwise
28+
*/
29+
public static long determineServiceTemplateInstanceId(final URI serviceInstanceID) {
30+
if (Objects.nonNull(serviceInstanceID)) {
31+
try {
32+
if (serviceInstanceID.toString().contains("/")) {
33+
return Long.parseLong(StringUtils.substringAfterLast(serviceInstanceID.toString(), "/"));
34+
} else {
35+
return Long.parseLong(serviceInstanceID.toString());
36+
}
37+
} catch (final NumberFormatException e) {
38+
LOG.error("Unable to parse ServiceTemplateInstance ID out of serviceInstanceID: {}", serviceInstanceID);
39+
}
40+
} else {
41+
LOG.error("Unable to parse ServiceTemplateInstance ID out of serviceInstanceID because it is null!");
42+
}
43+
return Long.MIN_VALUE;
44+
}
4345

44-
/**
45-
* Checks if a certain property was specified in the Tosca.xml of the ArtifactTemplate and returns it if so.
46-
*
47-
* @param artifactTemplate the ID of the ArtifactTemplate
48-
* @param propertyName the name of the property
49-
* @return the property value if specified, null otherwise
50-
*/
51-
public static String getProperty(final TArtifactTemplate artifactTemplate, final String propertyName) {
52-
final Document properties = ToscaEngine.getEntityTemplateProperties(artifactTemplate);
53-
// check if there are specified properties at all
54-
if (properties == null) {
55-
return null;
56-
}
46+
/**
47+
* Checks if a certain property was specified in the Tosca.xml of the
48+
* ArtifactTemplate and returns it if so.
49+
*
50+
* @param artifactTemplate the ID of the ArtifactTemplate
51+
* @param propertyName the name of the property
52+
* @return the property value if specified, null otherwise
53+
*/
54+
public static String getProperty(final TArtifactTemplate artifactTemplate, final String propertyName) {
55+
final Document properties = ToscaEngine.getEntityTemplateProperties(artifactTemplate);
56+
// check if there are specified properties at all
57+
if (properties == null || !properties.hasChildNodes()) {
58+
return null;
59+
}
5760

58-
final NodeList list = properties.getFirstChild().getChildNodes();
59-
// iterate through properties and check name
60-
for (int i = 0; i < list.getLength(); i++) {
61-
final Node propNode = list.item(i);
62-
final String localName = propNode.getLocalName();
63-
if (localName != null && localName.equals(propertyName)) {
64-
return propNode.getTextContent().trim();
65-
}
66-
}
67-
return null;
68-
}
61+
final NodeList list = properties.getFirstChild().getChildNodes();
62+
// iterate through properties and check name
63+
for (int i = 0; i < list.getLength(); i++) {
64+
final Node propNode = list.item(i);
65+
final String localName = propNode.getLocalName();
66+
if (localName != null && localName.equals(propertyName)) {
67+
return propNode.getTextContent().trim();
68+
}
69+
}
70+
return null;
71+
}
6972

70-
/**
71-
* Checks if a PortType property was specified in the Tosca.xml of the ArtifactTemplate and returns it if so.
72-
*
73-
* @param artifactTemplate the ArtifactTemplate
74-
* @return the PortType property value as QName if specified, null otherwise
75-
*/
76-
public static QName getPortTypeQName(final TArtifactTemplate artifactTemplate) {
77-
try {
78-
QName portType = QName.valueOf(getProperty(artifactTemplate, "PortType"));
79-
LOG.debug("PortType property: {}", portType.toString());
80-
return portType;
81-
} catch (final IllegalArgumentException e) {
82-
LOG.warn("PortType property can not be parsed to QName.");
83-
}
84-
return null;
85-
}
73+
/**
74+
* Checks if a PortType property was specified in the Tosca.xml of the
75+
* ArtifactTemplate and returns it if so.
76+
*
77+
* @param artifactTemplate the ArtifactTemplate
78+
* @return the PortType property value as QName if specified, null otherwise
79+
*/
80+
public static QName getPortTypeQName(final TArtifactTemplate artifactTemplate) {
81+
try {
82+
QName portType = QName.valueOf(getProperty(artifactTemplate, "PortType"));
83+
LOG.debug("PortType property: {}", portType.toString());
84+
return portType;
85+
} catch (final IllegalArgumentException e) {
86+
LOG.warn("PortType property can not be parsed to QName.");
87+
}
88+
return null;
89+
}
8690
}

0 commit comments

Comments
 (0)