diff options
author | Steve Smokowski <ss835w@att.com> | 2019-05-31 21:58:03 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-05-31 21:58:03 +0000 |
commit | b8bc4db00966393ea695d27641542d9a348ea129 (patch) | |
tree | ceb76967147462fe0690be0571ae4238170e0fe8 /common/src/main | |
parent | e2b0c39795a90aa7ac2abbc46b4f33793a9b8bd5 (diff) | |
parent | a8e40692a53109fde1eb6e977947db907a611287 (diff) |
Merge "apih resume request handling more generic"
Diffstat (limited to 'common/src/main')
-rw-r--r-- | common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java b/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java index 11cd3d42b7..34edf91c0c 100644 --- a/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java @@ -20,18 +20,75 @@ package org.onap.so.serviceinstancebeans; +import java.lang.reflect.InvocationTargetException; +import com.google.common.base.CaseFormat; + /* * Enum for Model Type values returned by API Handler to BPMN */ public enum ModelType { - service, - vnf, - vfModule, - volumeGroup, - network, - configuration, - connectionPoint, - pnf, - networkInstanceGroup, - instanceGroup + service("serviceInstance"), + vnf("vnf"), + vfModule("vfModule"), + volumeGroup("volumeGroup"), + network("network"), + configuration("configuration"), + connectionPoint("connectionPoint"), + pnf("pnf"), + networkInstanceGroup("networkInstanceGroup"), + instanceGroup("instanceGroup"); + + final String name; + + private ModelType(String name) { + this.name = name; + } + + + public <T> T getId(Object obj) { + return this.get(obj, "Id"); + } + + public <T> T getName(Object obj) { + return this.get(obj, "Name"); + } + + public void setId(Object obj, Object value) { + this.set(obj, "Id", value); + } + + public void setName(Object obj, Object value) { + this.set(obj, "Name", value); + } + + protected <T> T get(Object obj, String field) { + T result = null; + if (obj != null) { + try { + result = (T) obj.getClass().getMethod(String.format("%s%s%s", "get", + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this.name), field)).invoke(obj); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException | SecurityException e) { + // silent fail + } + } + + return result; + } + + protected void set(Object obj, String field, Object value) { + if (obj != null) { + try { + obj.getClass() + .getMethod( + String.format("%s%s%s", "set", + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this.name), field), + value.getClass()) + .invoke(obj, value); + } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { + // silent fail + } + } + } } |