diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-04-08 14:14:34 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-04-08 14:24:59 -0400 |
commit | f47919f1fe367b612fa9c96d34c59f01a541e882 (patch) | |
tree | 5b6aa2fc36747d868897e68ccbec0c6db0aee81c /adapters/mso-catalog-db-adapter/src/main | |
parent | 54452b80a1cf4d22ef750bc1377f8c1b05431d57 (diff) |
Replaced all tabs with spaces in java and pom.xml
Added in maven plugins to enforce coding style rules
Added in eclipse java formatting xml
Change-Id: I3727bbf4ce8dc66abfd8ad21b6cfd0890c5d3ff0
Issue-ID: SO-1765
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'adapters/mso-catalog-db-adapter/src/main')
19 files changed, 895 insertions, 916 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/db/migration/CloudConfig.java b/adapters/mso-catalog-db-adapter/src/main/java/db/migration/CloudConfig.java index 82139f21af..6a0bec5f08 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/db/migration/CloudConfig.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/db/migration/CloudConfig.java @@ -25,13 +25,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.onap.so.db.catalog.beans.CloudIdentity; import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.db.catalog.beans.CloudifyManager; - import java.util.HashMap; import java.util.Map; /** - * @deprecated - * This class is introduced as deprecated as its only purpose is for migration of cloud config data. It shouldnt be used elsewhere. + * @deprecated This class is introduced as deprecated as its only purpose is for migration of cloud config data. It + * shouldnt be used elsewhere. */ @Deprecated @@ -71,12 +70,12 @@ public class CloudConfig { this.cloudifyManagers = cloudifyManagers; } - public void populateId(){ + public void populateId() { for (Map.Entry<String, CloudIdentity> entry : identityServices.entrySet()) { entry.getValue().setId(entry.getKey()); } - for (Map.Entry <String, CloudSite> entry : cloudSites.entrySet()) { + for (Map.Entry<String, CloudSite> entry : cloudSites.entrySet()) { entry.getValue().setId(entry.getKey()); } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/db/migration/R__CloudConfigMigration.java b/adapters/mso-catalog-db-adapter/src/main/java/db/migration/R__CloudConfigMigration.java index c20acaf967..053c6da1cb 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/db/migration/R__CloudConfigMigration.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/db/migration/R__CloudConfigMigration.java @@ -35,7 +35,6 @@ import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.db.catalog.beans.CloudifyManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -48,56 +47,57 @@ import java.sql.Statement; import java.util.Collection; /** - * Performs migration using JDBC Connection from the cloud config provided in the environment (application-{profile}.yaml) and persist data (when not already present) to the catalod database. + * Performs migration using JDBC Connection from the cloud config provided in the environment + * (application-{profile}.yaml) and persist data (when not already present) to the catalod database. */ @JsonIgnoreProperties(ignoreUnknown = true) -public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoProvider, MigrationChecksumProvider { +public class R__CloudConfigMigration implements JdbcMigration, MigrationInfoProvider, MigrationChecksumProvider { public static final String FLYWAY = "FLYWAY"; private static final Logger logger = LoggerFactory.getLogger(R__CloudConfigMigration.class); @JsonProperty("cloud_config") private CloudConfig cloudConfig; - + @Override - public boolean isUndo(){ - return false; + public boolean isUndo() { + return false; } @Override public void migrate(Connection connection) throws Exception { logger.debug("Starting migration for CloudConfig"); - + CloudConfig cloudConfig = null; - + String tableQuery = "SELECT * FROM identity_services"; int totalRetries = 20; boolean tableExists = false; int count = 1; - while(!tableExists && count != totalRetries) { - try(Statement stmt = connection.createStatement();) { - stmt.executeQuery(tableQuery); - tableExists = true; + while (!tableExists && count != totalRetries) { + try (Statement stmt = connection.createStatement();) { + stmt.executeQuery(tableQuery); + tableExists = true; } catch (SQLException e) { - count++; - // Wait 5 mintues - Thread.sleep(300000); + count++; + // Wait 5 mintues + Thread.sleep(300000); } } - + // Try the override file String configLocation = System.getProperty("spring.config.additional-location"); if (configLocation != null) { try (InputStream stream = new FileInputStream(Paths.get(configLocation).normalize().toString())) { cloudConfig = loadCloudConfig(stream); - }catch(Exception e){ + } catch (Exception e) { logger.warn("Error Loading override.yaml", e); - } + } } - + if (cloudConfig == null) { logger.debug("No CloudConfig defined in {}", configLocation); - // Try the application.yaml file + // Try the application.yaml file try (InputStream stream = R__CloudConfigMigration.class.getResourceAsStream(getApplicationYamlName())) { cloudConfig = loadCloudConfig(stream); } @@ -106,8 +106,8 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro logger.debug("No CloudConfig defined in {}", getApplicationYamlName()); } } - - if(cloudConfig != null){ + + if (cloudConfig != null) { migrateCloudIdentity(cloudConfig.getIdentityServices().values(), connection); migrateCloudSite(cloudConfig.getCloudSites().values(), connection); migrateCloudifyManagers(cloudConfig.getCloudifyManagers().values(), connection); @@ -122,32 +122,35 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro this.cloudConfig = cloudConfig; } - private CloudConfig loadCloudConfig(InputStream stream) throws IOException { - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - R__CloudConfigMigration cloudConfigMigration = - mapper.readValue(stream, R__CloudConfigMigration.class); + private CloudConfig loadCloudConfig(InputStream stream) throws IOException { + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + R__CloudConfigMigration cloudConfigMigration = mapper.readValue(stream, R__CloudConfigMigration.class); CloudConfig cloudConfig = cloudConfigMigration.getCloudConfig(); - if(cloudConfig != null){ - cloudConfig.populateId(); + if (cloudConfig != null) { + cloudConfig.populateId(); } return cloudConfig; } private String getApplicationYamlName() { - String profile = System.getProperty("spring.profiles.active") == null ? "" : "-" + System.getProperty("spring.profiles.active"); + String profile = System.getProperty("spring.profiles.active") == null ? "" + : "-" + System.getProperty("spring.profiles.active"); return "/application" + profile + ".yaml"; } - private void migrateCloudIdentity(Collection<CloudIdentity> entities, Connection connection) throws SQLException { + private void migrateCloudIdentity(Collection<CloudIdentity> entities, Connection connection) throws SQLException { logger.debug("Starting migration for CloudConfig-->IdentityService"); - String insert = "INSERT INTO `identity_services` (`ID`, `IDENTITY_URL`, `MSO_ID`, `MSO_PASS`, `ADMIN_TENANT`, `MEMBER_ROLE`, `TENANT_METADATA`, `IDENTITY_SERVER_TYPE`, `IDENTITY_AUTHENTICATION_TYPE`, `LAST_UPDATED_BY`) " + - "VALUES (?,?,?,?,?,?,?,?,?,?);"; + String insert = + "INSERT INTO `identity_services` (`ID`, `IDENTITY_URL`, `MSO_ID`, `MSO_PASS`, `ADMIN_TENANT`, `MEMBER_ROLE`, `TENANT_METADATA`, `IDENTITY_SERVER_TYPE`, `IDENTITY_AUTHENTICATION_TYPE`, `LAST_UPDATED_BY`) " + + "VALUES (?,?,?,?,?,?,?,?,?,?);"; - try (Statement stmt = connection.createStatement();PreparedStatement ps = connection.prepareStatement(insert)) { + try (Statement stmt = connection.createStatement(); + PreparedStatement ps = connection.prepareStatement(insert)) { for (CloudIdentity cloudIdentity : entities) { - try (ResultSet rows = stmt.executeQuery("Select count(1) from identity_services where id='" + cloudIdentity.getId() + "'")) { + try (ResultSet rows = stmt.executeQuery( + "Select count(1) from identity_services where id='" + cloudIdentity.getId() + "'")) { int count = 0; while (rows.next()) { count = rows.getInt(1); @@ -160,8 +163,14 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro ps.setString(5, cloudIdentity.getAdminTenant()); ps.setString(6, cloudIdentity.getMemberRole()); ps.setBoolean(7, cloudIdentity.getTenantMetadata()); - ps.setString(8, cloudIdentity.getIdentityServerType() != null ? cloudIdentity.getIdentityServerType().name() : null); - ps.setString(9, cloudIdentity.getIdentityAuthenticationType() != null ? cloudIdentity.getIdentityAuthenticationType().name() : null); + ps.setString(8, + cloudIdentity.getIdentityServerType() != null + ? cloudIdentity.getIdentityServerType().name() + : null); + ps.setString(9, + cloudIdentity.getIdentityAuthenticationType() != null + ? cloudIdentity.getIdentityAuthenticationType().name() + : null); ps.setString(10, FLYWAY); ps.executeUpdate(); } @@ -170,14 +179,17 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro } } - private void migrateCloudSite(Collection<CloudSite> entities, Connection connection) throws SQLException { + private void migrateCloudSite(Collection<CloudSite> entities, Connection connection) throws SQLException { logger.debug("Starting migration for CloudConfig-->CloudSite"); - String insert = "INSERT INTO `cloud_sites` (`ID`, `REGION_ID`, `IDENTITY_SERVICE_ID`, `CLOUD_VERSION`, `CLLI`, `CLOUDIFY_ID`, `PLATFORM`, `ORCHESTRATOR`, `LAST_UPDATED_BY`) " + - "VALUES (?,?,?,?,?,?,?,?,?);"; + String insert = + "INSERT INTO `cloud_sites` (`ID`, `REGION_ID`, `IDENTITY_SERVICE_ID`, `CLOUD_VERSION`, `CLLI`, `CLOUDIFY_ID`, `PLATFORM`, `ORCHESTRATOR`, `LAST_UPDATED_BY`) " + + "VALUES (?,?,?,?,?,?,?,?,?);"; - try (Statement stmt = connection.createStatement();PreparedStatement ps = connection.prepareStatement(insert)) { + try (Statement stmt = connection.createStatement(); + PreparedStatement ps = connection.prepareStatement(insert)) { for (CloudSite cloudSite : entities) { - try (ResultSet rows = stmt.executeQuery("Select count(1) from cloud_sites where id='" + cloudSite.getId() + "'")) { + try (ResultSet rows = + stmt.executeQuery("Select count(1) from cloud_sites where id='" + cloudSite.getId() + "'")) { int count = 0; while (rows.next()) { count = rows.getInt(1); @@ -199,13 +211,17 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro } } - private void migrateCloudifyManagers(Collection<CloudifyManager> entities, Connection connection) throws SQLException { - String insert = "INSERT INTO `cloudify_managers` (`ID`, `CLOUDIFY_URL`, `USERNAME`, `PASSWORD`, `VERSION`, `LAST_UPDATED_BY`)" + - " VALUES (?,?,?,?,?,?);"; + private void migrateCloudifyManagers(Collection<CloudifyManager> entities, Connection connection) + throws SQLException { + String insert = + "INSERT INTO `cloudify_managers` (`ID`, `CLOUDIFY_URL`, `USERNAME`, `PASSWORD`, `VERSION`, `LAST_UPDATED_BY`)" + + " VALUES (?,?,?,?,?,?);"; - try (Statement stmt = connection.createStatement();PreparedStatement ps = connection.prepareStatement(insert)) { + try (Statement stmt = connection.createStatement(); + PreparedStatement ps = connection.prepareStatement(insert)) { for (CloudifyManager cloudifyManager : entities) { - try (ResultSet rows = stmt.executeQuery("Select count(1) from cloudify_managers where id='" + cloudifyManager.getId() + "'")) { + try (ResultSet rows = stmt.executeQuery( + "Select count(1) from cloudify_managers where id='" + cloudifyManager.getId() + "'")) { int count = 0; while (rows.next()) { count = rows.getInt(1); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBApplication.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBApplication.java index 374e597116..a0a0756d3d 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBApplication.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDBApplication.java @@ -25,23 +25,25 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -@SpringBootApplication(scanBasePackages = {"org.onap.so.adapters.catalogdb", "org.onap.so.db.catalog.client","org.onap.so.logging.jaxrs.filter","org.onap.so.logging.spring.interceptor","org.onap.so.client","org.onap.so.configuration"}) +@SpringBootApplication(scanBasePackages = {"org.onap.so.adapters.catalogdb", "org.onap.so.db.catalog.client", + "org.onap.so.logging.jaxrs.filter", "org.onap.so.logging.spring.interceptor", "org.onap.so.client", + "org.onap.so.configuration"}) @EnableJpaRepositories("org.onap.so.db.catalog.data.repository") @EntityScan("org.onap.so.db.catalog.beans") public class CatalogDBApplication { - - private static final String LOGS_DIR = "logs_dir"; - private static void setLogsDir() { - if (System.getProperty(LOGS_DIR) == null) { - System.getProperties().setProperty(LOGS_DIR, "./logs/catdb/"); - } - } - + private static final String LOGS_DIR = "logs_dir"; + + private static void setLogsDir() { + if (System.getProperty(LOGS_DIR) == null) { + System.getProperties().setProperty(LOGS_DIR, "./logs/catdb/"); + } + } + public static void main(String[] args) { SpringApplication.run(CatalogDBApplication.class, args); System.getProperties().setProperty("mso.db", "MARIADB"); - System.getProperties().setProperty("server.name", "Springboot"); + System.getProperties().setProperty("server.name", "Springboot"); setLogsDir(); } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDbRepositoryConfiguration.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDbRepositoryConfiguration.java index 3906762e60..fdec7cf5d6 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDbRepositoryConfiguration.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/CatalogDbRepositoryConfiguration.java @@ -21,9 +21,7 @@ package org.onap.so.adapters.catalogdb; import java.util.stream.Collectors; - import javax.persistence.EntityManager; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; @@ -32,12 +30,13 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapt @Configuration public class CatalogDbRepositoryConfiguration extends RepositoryRestConfigurerAdapter { - @Autowired - private EntityManager entityManager; + @Autowired + private EntityManager entityManager; - @Override - public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { - config.exposeIdsFor(entityManager.getMetamodel().getEntities().stream().map(e -> e.getJavaType()).collect(Collectors.toList()).toArray(new Class[0])); - } + @Override + public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { + config.exposeIdsFor(entityManager.getMetamodel().getEntities().stream().map(e -> e.getJavaType()) + .collect(Collectors.toList()).toArray(new Class[0])); + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java index ff162c862e..db73d4afec 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java @@ -22,12 +22,10 @@ package org.onap.so.adapters.catalogdb; import javax.annotation.PostConstruct; import javax.ws.rs.ApplicationPath; - import org.glassfish.jersey.server.ResourceConfig; import org.onap.so.adapters.catalogdb.rest.CatalogDbAdapterRest; import org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging; import org.springframework.context.annotation.Configuration; - import io.swagger.jaxrs.config.BeanConfig; import io.swagger.jaxrs.listing.ApiListingResource; import io.swagger.jaxrs.listing.SwaggerSerializers; @@ -36,20 +34,20 @@ import io.swagger.jaxrs.listing.SwaggerSerializers; @ApplicationPath("/ecomp/mso/catalog") public class JerseyConfiguration extends ResourceConfig { - @PostConstruct - public void setUp() { - register(CatalogDbAdapterRest.class); - register(ApiListingResource.class); - register(SwaggerSerializers.class); - register(JaxRsFilterLogging.class); - BeanConfig beanConfig = new BeanConfig(); - beanConfig.setVersion("1.0.2"); - beanConfig.setSchemes(new String[]{"http"}); - beanConfig.setHost("localhost:8080"); - beanConfig.setBasePath("/ecomp/mso/catalog"); - beanConfig.setResourcePackage("org.onap.so.adapters.catalogdb"); - beanConfig.setPrettyPrint(true); - beanConfig.setScan(true); - } + @PostConstruct + public void setUp() { + register(CatalogDbAdapterRest.class); + register(ApiListingResource.class); + register(SwaggerSerializers.class); + register(JaxRsFilterLogging.class); + BeanConfig beanConfig = new BeanConfig(); + beanConfig.setVersion("1.0.2"); + beanConfig.setSchemes(new String[] {"http"}); + beanConfig.setHost("localhost:8080"); + beanConfig.setBasePath("/ecomp/mso/catalog"); + beanConfig.setResourcePackage("org.onap.so.adapters.catalogdb"); + beanConfig.setPrettyPrint(true); + beanConfig.setScan(true); + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebMvcConfig.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebMvcConfig.java index efe6010f23..4dabb58f7d 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebMvcConfig.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebMvcConfig.java @@ -36,7 +36,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { @Bean public MappedInterceptor mappedLoggingInterceptor() { - return new MappedInterceptor(new String[]{"/**"}, loggingInterceptor); + return new MappedInterceptor(new String[] {"/**"}, loggingInterceptor); } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebSecurityConfigImpl.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebSecurityConfigImpl.java index 2eb4858803..1d58975e6b 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebSecurityConfigImpl.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/WebSecurityConfigImpl.java @@ -33,21 +33,18 @@ import org.springframework.util.StringUtils; @EnableWebSecurity public class WebSecurityConfigImpl extends WebSecurityConfig { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable() - .authorizeRequests() - .antMatchers("/manage/health","/manage/info").permitAll() - .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(),",")) - .and() - .httpBasic(); - } - - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); - StrictHttpFirewall firewall = new MSOSpringFirewall(); - web.httpFirewall(firewall); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll() + .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")).and() + .httpBasic(); + } + + @Override + public void configure(WebSecurity web) throws Exception { + super.configure(web); + StrictHttpFirewall firewall = new MSOSpringFirewall(); + web.httpFirewall(firewall); + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java index cc1b3ddb17..edec48dc95 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java @@ -29,68 +29,70 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.ObjectMapper; public abstract class CatalogQuery { - protected static Logger logger = LoggerFactory.getLogger(CatalogQuery.class); - private static final boolean IS_EMBED = true; + protected static Logger logger = LoggerFactory.getLogger(CatalogQuery.class); + private static final boolean IS_EMBED = true; - public abstract String JSON2(boolean isArray, boolean isEmbed); + public abstract String JSON2(boolean isArray, boolean isEmbed); - protected void put(Map<String, String> valueMap, String key, String value) { - valueMap.put(key, value == null? "null": '"'+ value+ '"'); - } + protected void put(Map<String, String> valueMap, String key, String value) { + valueMap.put(key, value == null ? "null" : '"' + value + '"'); + } - protected void put(Map<String, String> valueMap, String key, Integer value) { - valueMap.put(key, value == null? "null": value.toString()); - } + protected void put(Map<String, String> valueMap, String key, Integer value) { + valueMap.put(key, value == null ? "null" : value.toString()); + } - protected void put(Map<String, String> valueMap, String key, Boolean value) { - valueMap.put(key, value == null? "null": value? "true": "false"); - } + protected void put(Map<String, String> valueMap, String key, Boolean value) { + valueMap.put(key, value == null ? "null" : value ? "true" : "false"); + } - protected String setTemplate(String template, Map<String, String> valueMap) { - StringBuffer result = new StringBuffer(); + protected String setTemplate(String template, Map<String, String> valueMap) { + StringBuffer result = new StringBuffer(); - String pattern = "<.*>"; - Pattern r = Pattern.compile(pattern); - Matcher m = r.matcher(template); + String pattern = "<.*>"; + Pattern r = Pattern.compile(pattern); + Matcher m = r.matcher(template); - logger.debug("CatalogQuery template: {}", template); - while (m.find()) { - String key = template.substring(m.start() + 1, m.end() - 1); - logger.debug("CatalogQuery key: {} contains key? {}", key , valueMap.containsKey(key)); - m.appendReplacement(result, Matcher.quoteReplacement(valueMap.getOrDefault(key, "\"TBD\""))); - } - m.appendTail(result); - logger.debug("CatalogQuery return: {}", result.toString()); - return result.toString(); - } + logger.debug("CatalogQuery template: {}", template); + while (m.find()) { + String key = template.substring(m.start() + 1, m.end() - 1); + logger.debug("CatalogQuery key: {} contains key? {}", key, valueMap.containsKey(key)); + m.appendReplacement(result, Matcher.quoteReplacement(valueMap.getOrDefault(key, "\"TBD\""))); + } + m.appendTail(result); + logger.debug("CatalogQuery return: {}", result.toString()); + return result.toString(); + } - /** - * The simple, clean, generic way to handle the interface - */ - protected String smartToJSON() { - String jsonString = null; - try { - ObjectMapper mapper = new ObjectMapper(); - jsonString = mapper.writeValueAsString(this); - } - catch (Exception e) { - logger.error("Error converting to JSON" , e); - jsonString = "invalid"; //throws instead? - } - return jsonString; - } + /** + * The simple, clean, generic way to handle the interface + */ + protected String smartToJSON() { + String jsonString = null; + try { + ObjectMapper mapper = new ObjectMapper(); + jsonString = mapper.writeValueAsString(this); + } catch (Exception e) { + logger.error("Error converting to JSON", e); + jsonString = "invalid"; // throws instead? + } + return jsonString; + } - public String toJsonString(String version, boolean isArray) { - switch(version) { - case "v1": return smartToJSON(); - case "v2": return JSON2(isArray, !IS_EMBED); - default: - return "invalid version: "+ version; - } - } - @Override - public String toString(){ - return smartToJSON(); - - } + public String toJsonString(String version, boolean isArray) { + switch (version) { + case "v1": + return smartToJSON(); + case "v2": + return JSON2(isArray, !IS_EMBED); + default: + return "invalid version: " + version; + } + } + + @Override + public String toString() { + return smartToJSON(); + + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryException.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryException.java index 890347344c..f47c9006c6 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryException.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryException.java @@ -21,7 +21,6 @@ package org.onap.so.adapters.catalogdb.catalogrest; import java.io.Serializable; - import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "catalogQueryException") @@ -29,30 +28,46 @@ public class CatalogQueryException extends CatalogQueryExceptionCommon implement private static final long serialVersionUID = -9062290006520066109L; private String message; - private CatalogQueryExceptionCategory category; - private Boolean rolledBack; + private CatalogQueryExceptionCategory category; + private Boolean rolledBack; + + public CatalogQueryException() {} + + public CatalogQueryException(String message) { + this.message = message; + } + + public CatalogQueryException(String message, CatalogQueryExceptionCategory category, boolean rolledBack, + String messageid) { + super(messageid); + this.message = message; + this.category = category; + this.rolledBack = rolledBack; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } - public CatalogQueryException () {} + public CatalogQueryExceptionCategory getCategory() { + return category; + } - public CatalogQueryException (String message) { - this.message = message; - } + public void setCategory(CatalogQueryExceptionCategory category) { + this.category = category; + } - public CatalogQueryException (String message, CatalogQueryExceptionCategory category, boolean rolledBack, String messageid) { - super(messageid); - this.message = message; - this.category = category; - this.rolledBack = rolledBack; - } + public Boolean getRolledBack() { + return rolledBack; + } - public String getMessage() { return message; } - public void setMessage(String message) { this.message = message; } + public void setRolledBack(Boolean rolledBack) { + this.rolledBack = rolledBack; + } - public CatalogQueryExceptionCategory getCategory () { return category; } - public void setCategory (CatalogQueryExceptionCategory category) { this.category = category; } - public Boolean getRolledBack() { return rolledBack; } - public void setRolledBack(Boolean rolledBack) { this.rolledBack = rolledBack; } - - } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryExceptionCategory.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryExceptionCategory.java index 687cc7d3e0..d22c865555 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryExceptionCategory.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryExceptionCategory.java @@ -20,4 +20,6 @@ package org.onap.so.adapters.catalogdb.catalogrest; -public enum CatalogQueryExceptionCategory { OPENSTACK, IO, INTERNAL, USERDATA } +public enum CatalogQueryExceptionCategory { + OPENSTACK, IO, INTERNAL, USERDATA +} diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryExceptionCommon.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryExceptionCommon.java index 283fef1d3b..324ac073a8 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryExceptionCommon.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQueryExceptionCommon.java @@ -24,54 +24,62 @@ package org.onap.so.adapters.catalogdb.catalogrest; import java.io.ByteArrayOutputStream; - import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; public abstract class CatalogQueryExceptionCommon { - private String messageId; - protected static Logger logger = LoggerFactory.getLogger(CatalogQueryExceptionCommon.class); + private String messageId; + protected static Logger logger = LoggerFactory.getLogger(CatalogQueryExceptionCommon.class); + + public CatalogQueryExceptionCommon() { + messageId = null; + } + + public CatalogQueryExceptionCommon(String messageId) { + this.messageId = messageId; + } + + public String getMessageId() { + return messageId; + } - public CatalogQueryExceptionCommon() { messageId = null; } - public CatalogQueryExceptionCommon(String messageId) { this.messageId = messageId; } + public void setMessageId(String messageId) { + this.messageId = messageId; + } - public String getMessageId() { return messageId; } - public void setMessageId(String messageId) { this.messageId = messageId; } + public String toJsonString() { + try { + String jsonString; + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + jsonString = mapper.writeValueAsString(this); + return jsonString; + } catch (Exception e) { + logger.error("Exception:", e); + return ""; + } + } - public String toJsonString() { - try { - String jsonString; - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); - jsonString = mapper.writeValueAsString(this); - return jsonString; - } catch (Exception e) { - logger.error ("Exception:", e); - return ""; - } - } + public String toXmlString() { + try { + ByteArrayOutputStream bs = new ByteArrayOutputStream(); + JAXBContext context = JAXBContext.newInstance(this.getClass()); + Marshaller marshaller = context.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // pretty print XML + marshaller.marshal(this, bs); + return bs.toString(); + } catch (Exception e) { + logger.error("Exception:", e); + return ""; + } + } - public String toXmlString() { - try { - ByteArrayOutputStream bs = new ByteArrayOutputStream(); - JAXBContext context = JAXBContext.newInstance(this.getClass()); - Marshaller marshaller = context.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //pretty print XML - marshaller.marshal(this, bs); - return bs.toString(); - } catch (Exception e) { - logger.error ("Exception:", e); - return ""; - } - } - - @Override - public String toString(){ - return toJsonString(); - } + @Override + public String toString() { + return toJsonString(); + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java index 859666f446..e550394931 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java @@ -32,116 +32,113 @@ import org.slf4j.LoggerFactory; @XmlRootElement(name = "serviceAllottedResources") public class QueryAllottedResourceCustomization extends CatalogQuery { protected static Logger logger = LoggerFactory.getLogger(QueryAllottedResourceCustomization.class); - private List<AllottedResourceCustomization> allottedResourceCustomization; - private static final String TEMPLATE = - "\t{\n"+ - "\t\t\"modelInfo\" : {\n"+ - "\t\t\t\"modelName\" : <MODEL_NAME>,\n"+ - "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ - "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ - "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ - "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+ - "\t\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n"+ - "\t\t},\n"+ - "\t\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n"+ - "\t\t\"allottedResourceType\" : <ALLOTTED_RESOURCE_TYPE>,\n"+ - "\t\t\"allottedResourceRole\" : <ALLOTTED_RESOURCE_ROLE>,\n"+ - "\t\t\"providingServiceModelName\" : <PROVIDING_SERVICE_MODEL_NAME>,\n"+ - "\t\t\"providingServiceModelInvariantUuid\" : <PROVIDING_SERVICE_MODEL_INVARIANT_UUID>,\n"+ - "\t\t\"providingServiceModelUuid\" : <PROVIDING_SERVICE_MODEL_UUID>,\n"+ - "\t\t\"nfFunction\" : <NF_FUNCTION>,\n"+ - "\t\t\"nfType\" : <NF_TYPE>,\n"+ - "\t\t\"nfRole\" : <NF_ROLE>,\n"+ - "\t\t\"nfNamingCode\" : <NF_NAMING_CODE>,\n"+ - "\t\t\"resourceInput\" : <RESOURCE_INPUT>\n"+ - "\t}"; - - public QueryAllottedResourceCustomization() { - super(); - allottedResourceCustomization = new ArrayList<>(); - } - - public QueryAllottedResourceCustomization(List<AllottedResourceCustomization> vlist) { - allottedResourceCustomization = vlist; - } - - public List<AllottedResourceCustomization> getServiceAllottedResources(){ - return this.allottedResourceCustomization; - } - - public void setServiceAllottedResources(List<AllottedResourceCustomization> v) { - this.allottedResourceCustomization = v; - } - - @Override - public String toString () { - StringBuilder sb = new StringBuilder(); - - boolean first = true; - int i = 1; - for (AllottedResourceCustomization o : allottedResourceCustomization) { - sb.append(i).append("\t"); - if (!first) - sb.append("\n"); - - first = false; - sb.append(o); - } - return sb.toString(); + private List<AllottedResourceCustomization> allottedResourceCustomization; + private static final String TEMPLATE = + "\t{\n" + "\t\t\"modelInfo\" : {\n" + "\t\t\t\"modelName\" : <MODEL_NAME>,\n" + + "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n" + + "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n" + + "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n" + + "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n" + + "\t\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n" + "\t\t},\n" + + "\t\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n" + + "\t\t\"allottedResourceType\" : <ALLOTTED_RESOURCE_TYPE>,\n" + + "\t\t\"allottedResourceRole\" : <ALLOTTED_RESOURCE_ROLE>,\n" + + "\t\t\"providingServiceModelName\" : <PROVIDING_SERVICE_MODEL_NAME>,\n" + + "\t\t\"providingServiceModelInvariantUuid\" : <PROVIDING_SERVICE_MODEL_INVARIANT_UUID>,\n" + + "\t\t\"providingServiceModelUuid\" : <PROVIDING_SERVICE_MODEL_UUID>,\n" + + "\t\t\"nfFunction\" : <NF_FUNCTION>,\n" + + "\t\t\"nfType\" : <NF_TYPE>,\n" + + "\t\t\"nfRole\" : <NF_ROLE>,\n" + + "\t\t\"nfNamingCode\" : <NF_NAMING_CODE>,\n" + + "\t\t\"resourceInput\" : <RESOURCE_INPUT>\n" + "\t}"; + + public QueryAllottedResourceCustomization() { + super(); + allottedResourceCustomization = new ArrayList<>(); + } + + public QueryAllottedResourceCustomization(List<AllottedResourceCustomization> vlist) { + allottedResourceCustomization = vlist; + } + + public List<AllottedResourceCustomization> getServiceAllottedResources() { + return this.allottedResourceCustomization; + } + + public void setServiceAllottedResources(List<AllottedResourceCustomization> v) { + this.allottedResourceCustomization = v; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + boolean first = true; + int i = 1; + for (AllottedResourceCustomization o : allottedResourceCustomization) { + sb.append(i).append("\t"); + if (!first) + sb.append("\n"); + + first = false; + sb.append(o); + } + return sb.toString(); } - @Override - public String JSON2(boolean isArray, boolean isEmbed) { - StringBuilder sb = new StringBuilder(); - if (!isEmbed && isArray) - sb.append("{ "); - if (isArray) - sb.append("\"serviceAllottedResources\": ["); - Map<String, String> valueMap = new HashMap<>(); - String sep = ""; - boolean first = true; - - if (this.allottedResourceCustomization != null) { - for (AllottedResourceCustomization o : allottedResourceCustomization) { - if (first) - sb.append("\n"); - - first = false; - - boolean arNull = o.getAllottedResource() == null ? true : false; - - put(valueMap, "MODEL_NAME", arNull ? null : o.getAllottedResource().getModelName()); - put(valueMap, "MODEL_UUID", arNull ? null : o.getAllottedResource().getModelUUID()); - put(valueMap, "MODEL_INVARIANT_ID", arNull ? null : o.getAllottedResource().getModelInvariantUUID()); - put(valueMap, "MODEL_VERSION", arNull ? null : o.getAllottedResource().getModelVersion()); - put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); - put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName()); - put(valueMap, "TOSCA_NODE_TYPE", arNull ? null : o.getAllottedResource().getToscaNodeType()); - put(valueMap, "ALLOTTED_RESOURCE_TYPE", arNull ? null : o.getAllottedResource().getSubcategory()); - put(valueMap, "ALLOTTED_RESOURCE_ROLE", o.getTargetNetworkRole() != null ? o.getTargetNetworkRole() : o.getNfRole()); - put(valueMap, "NF_TYPE", o.getNfType()); - put(valueMap, "NF_ROLE", o.getNfRole()); - put(valueMap, "NF_FUNCTION", o.getNfFunction()); - put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode()); - put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID", o.getProvidingServiceModelInvariantUUID()); - put(valueMap, "PROVIDING_SERVICE_MODEL_UUID", o.getProvidingServiceModelUUID()); - put(valueMap, "PROVIDING_SERVICE_MODEL_NAME", o.getProvidingServiceModelName()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); - - sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); - sep = ",\n"; - } - } - if (!first) - sb.append("\n"); - - if (isArray) - sb.append("]"); - - if (!isEmbed && isArray) - sb.append("}"); - - return sb.toString(); - } + @Override + public String JSON2(boolean isArray, boolean isEmbed) { + StringBuilder sb = new StringBuilder(); + if (!isEmbed && isArray) + sb.append("{ "); + if (isArray) + sb.append("\"serviceAllottedResources\": ["); + Map<String, String> valueMap = new HashMap<>(); + String sep = ""; + boolean first = true; + + if (this.allottedResourceCustomization != null) { + for (AllottedResourceCustomization o : allottedResourceCustomization) { + if (first) + sb.append("\n"); + + first = false; + + boolean arNull = o.getAllottedResource() == null ? true : false; + + put(valueMap, "MODEL_NAME", arNull ? null : o.getAllottedResource().getModelName()); + put(valueMap, "MODEL_UUID", arNull ? null : o.getAllottedResource().getModelUUID()); + put(valueMap, "MODEL_INVARIANT_ID", arNull ? null : o.getAllottedResource().getModelInvariantUUID()); + put(valueMap, "MODEL_VERSION", arNull ? null : o.getAllottedResource().getModelVersion()); + put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); + put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName()); + put(valueMap, "TOSCA_NODE_TYPE", arNull ? null : o.getAllottedResource().getToscaNodeType()); + put(valueMap, "ALLOTTED_RESOURCE_TYPE", arNull ? null : o.getAllottedResource().getSubcategory()); + put(valueMap, "ALLOTTED_RESOURCE_ROLE", + o.getTargetNetworkRole() != null ? o.getTargetNetworkRole() : o.getNfRole()); + put(valueMap, "NF_TYPE", o.getNfType()); + put(valueMap, "NF_ROLE", o.getNfRole()); + put(valueMap, "NF_FUNCTION", o.getNfFunction()); + put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode()); + put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID", o.getProvidingServiceModelInvariantUUID()); + put(valueMap, "PROVIDING_SERVICE_MODEL_UUID", o.getProvidingServiceModelUUID()); + put(valueMap, "PROVIDING_SERVICE_MODEL_NAME", o.getProvidingServiceModelName()); + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + + sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); + sep = ",\n"; + } + } + if (!first) + sb.append("\n"); + + if (isArray) + sb.append("]"); + + if (!isEmbed && isArray) + sb.append("}"); + + return sb.toString(); + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipe.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipe.java index 58a2e852f0..ee52abe047 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipe.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipe.java @@ -21,7 +21,6 @@ package org.onap.so.adapters.catalogdb.catalogrest; import java.util.HashMap; import java.util.Map; - import org.apache.commons.lang3.StringUtils; import org.onap.so.db.catalog.beans.Recipe; import org.slf4j.Logger; @@ -31,21 +30,20 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; /** - * serivce csar query support - * <br> + * serivce csar query support <br> * <p> * </p> * * @author - * @version ONAP Beijing Release 2018-02-28 + * @version ONAP Beijing Release 2018-02-28 */ -public class QueryResourceRecipe extends CatalogQuery{ +public class QueryResourceRecipe extends CatalogQuery { protected static Logger logger = LoggerFactory.getLogger(QueryResourceRecipe.class); - + private Recipe resourceRecipe; - - public QueryResourceRecipe(Recipe resourceRecipe){ - this.resourceRecipe =resourceRecipe; + + public QueryResourceRecipe(Recipe resourceRecipe) { + this.resourceRecipe = resourceRecipe; } @Override @@ -56,25 +54,28 @@ public class QueryResourceRecipe extends CatalogQuery{ @Override public String JSON2(boolean isArray, boolean isEmbed) { - Map<String, String> valueMap = new HashMap<>(); - valueMap.put("id", null == resourceRecipe || null == resourceRecipe.getId() - ? StringUtils.EMPTY :String.valueOf(resourceRecipe.getId())); - valueMap.put("action", null == resourceRecipe || null == resourceRecipe.getAction() - ? StringUtils.EMPTY :resourceRecipe.getAction()); - valueMap.put("orchestrationUri", null == resourceRecipe || null == resourceRecipe.getOrchestrationUri() - ? StringUtils.EMPTY : resourceRecipe.getOrchestrationUri()); - valueMap.put("recipeTimeout", null == resourceRecipe || null == resourceRecipe.getRecipeTimeout() - ? StringUtils.EMPTY : String.valueOf(resourceRecipe.getRecipeTimeout())); - valueMap.put("paramXSD", null == resourceRecipe || null == resourceRecipe.getParamXsd() - ? StringUtils.EMPTY : resourceRecipe.getParamXsd()); - valueMap.put("description", null == resourceRecipe || null == resourceRecipe.getDescription() - ? StringUtils.EMPTY : resourceRecipe.getDescription()); + Map<String, String> valueMap = new HashMap<>(); + valueMap.put("id", null == resourceRecipe || null == resourceRecipe.getId() ? StringUtils.EMPTY + : String.valueOf(resourceRecipe.getId())); + valueMap.put("action", null == resourceRecipe || null == resourceRecipe.getAction() ? StringUtils.EMPTY + : resourceRecipe.getAction()); + valueMap.put("orchestrationUri", + null == resourceRecipe || null == resourceRecipe.getOrchestrationUri() ? StringUtils.EMPTY + : resourceRecipe.getOrchestrationUri()); + valueMap.put("recipeTimeout", + null == resourceRecipe || null == resourceRecipe.getRecipeTimeout() ? StringUtils.EMPTY + : String.valueOf(resourceRecipe.getRecipeTimeout())); + valueMap.put("paramXSD", null == resourceRecipe || null == resourceRecipe.getParamXsd() ? StringUtils.EMPTY + : resourceRecipe.getParamXsd()); + valueMap.put("description", + null == resourceRecipe || null == resourceRecipe.getDescription() ? StringUtils.EMPTY + : resourceRecipe.getDescription()); ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); String jsonStr = ""; try { jsonStr = mapper.writeValueAsString(valueMap); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { logger.error("Error creating JSON", e); } return jsonStr; diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceCsar.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceCsar.java index c7ae137759..1afd395136 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceCsar.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceCsar.java @@ -21,36 +21,29 @@ package org.onap.so.adapters.catalogdb.catalogrest; import java.util.HashMap; import java.util.Map; - import org.onap.so.db.catalog.beans.ToscaCsar; /** - * serivce csar query support - * <br> + * serivce csar query support <br> * <p> * </p> * * @author - * @version ONAP Beijing Release 2018-02-28 + * @version ONAP Beijing Release 2018-02-28 */ -public class QueryServiceCsar extends CatalogQuery{ - - private static final String TEMPLATE = - "\t{\n"+ - "\t\t\"artifactUUID\" : <ARTIFACT_UUID>,\n"+ - "\t\t\"name\" : <NAME>,\n"+ - "\t\t\"version\" : <VERSION>,\n"+ - "\t\t\"artifactChecksum\" : <ARTIFACT_CHECK_SUM>,\n"+ - "\t\t\"url\" : <URL>,\n"+ - "\t\t\"description\" : <DESCRIPTION>\n"+ - "\t}"; - +public class QueryServiceCsar extends CatalogQuery { + + private static final String TEMPLATE = "\t{\n" + "\t\t\"artifactUUID\" : <ARTIFACT_UUID>,\n" + + "\t\t\"name\" : <NAME>,\n" + "\t\t\"version\" : <VERSION>,\n" + + "\t\t\"artifactChecksum\" : <ARTIFACT_CHECK_SUM>,\n" + "\t\t\"url\" : <URL>,\n" + + "\t\t\"description\" : <DESCRIPTION>\n" + "\t}"; + private ToscaCsar toscaCsar; - - public QueryServiceCsar(ToscaCsar toscaCsar){ + + public QueryServiceCsar(ToscaCsar toscaCsar) { this.toscaCsar = toscaCsar; } - + @Override public String toString() { return toscaCsar.toString(); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java index edbf9749c6..0eb7d0418e 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java @@ -19,14 +19,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - + package org.onap.so.adapters.catalogdb.catalogrest; import java.util.HashMap; import java.util.Map; - import javax.xml.bind.annotation.XmlRootElement; - import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.rest.beans.ServiceMacroHolder; @@ -34,68 +32,70 @@ import org.onap.so.db.catalog.rest.beans.ServiceMacroHolder; public class QueryServiceMacroHolder extends CatalogQuery { private ServiceMacroHolder serviceMacroHolder; private static final String LINE_BEGINNING = "(?m)^"; - private static final String TEMPLATE = - "{ \"serviceResources\" : {\n"+ - "\t\"modelInfo\" : {\n"+ - "\t\t\"modelName\" : <SERVICE_MODEL_NAME>,\n"+ - "\t\t\"modelUuid\" : <SERVICE_MODEL_UUID>,\n"+ - "\t\t\"modelInvariantUuid\" : <SERVICE_MODEL_INVARIANT_ID>,\n"+ - "\t\t\"modelVersion\" : <SERVICE_MODEL_VERSION>\n"+ - "\t},\n"+ - "\t\"serviceType\" : <SERVICE_TYPE>,\n"+ - "\t\"serviceRole\" : <SERVICE_ROLE>,\n"+ - "\t\"environmentContext\" : <ENVIRONMENT_CONTEXT>,\n"+ - "\t\"resourceOrder\" : <RESOURCE_ORDER>,\n"+ - "\t\"workloadContext\" : <WORKLOAD_CONTEXT>,\n"+ - "<_SERVICEVNFS_>,\n"+ - "<_SERVICENETWORKS_>,\n"+ - "<_SERVICEALLOTTEDRESOURCES_>\n"+ - "\t}}"; - - public QueryServiceMacroHolder() { - super(); - serviceMacroHolder = new ServiceMacroHolder(); - } - public QueryServiceMacroHolder(ServiceMacroHolder vlist) { serviceMacroHolder = vlist; } - - public ServiceMacroHolder getServiceResources(){ return this.serviceMacroHolder; } - public void setServiceResources(ServiceMacroHolder v) { this.serviceMacroHolder = v; } - - @Override - public String toString () { return serviceMacroHolder.toString(); } - - @Override - public String JSON2(boolean isArray, boolean x) { - Service service = serviceMacroHolder.getService(); - if (service == null) { + private static final String TEMPLATE = "{ \"serviceResources\" : {\n" + "\t\"modelInfo\" : {\n" + + "\t\t\"modelName\" : <SERVICE_MODEL_NAME>,\n" + + "\t\t\"modelUuid\" : <SERVICE_MODEL_UUID>,\n" + + "\t\t\"modelInvariantUuid\" : <SERVICE_MODEL_INVARIANT_ID>,\n" + + "\t\t\"modelVersion\" : <SERVICE_MODEL_VERSION>\n" + "\t},\n" + + "\t\"serviceType\" : <SERVICE_TYPE>,\n" + "\t\"serviceRole\" : <SERVICE_ROLE>,\n" + + "\t\"environmentContext\" : <ENVIRONMENT_CONTEXT>,\n" + "\t\"resourceOrder\" : <RESOURCE_ORDER>,\n" + + "\t\"workloadContext\" : <WORKLOAD_CONTEXT>,\n" + "<_SERVICEVNFS_>,\n" + "<_SERVICENETWORKS_>,\n" + + "<_SERVICEALLOTTEDRESOURCES_>\n" + "\t}}"; + + public QueryServiceMacroHolder() { + super(); + serviceMacroHolder = new ServiceMacroHolder(); + } + + public QueryServiceMacroHolder(ServiceMacroHolder vlist) { + serviceMacroHolder = vlist; + } + + public ServiceMacroHolder getServiceResources() { + return this.serviceMacroHolder; + } + + public void setServiceResources(ServiceMacroHolder v) { + this.serviceMacroHolder = v; + } + + @Override + public String toString() { + return serviceMacroHolder.toString(); + } + + @Override + public String JSON2(boolean isArray, boolean x) { + Service service = serviceMacroHolder.getService(); + if (service == null) { return "\"serviceResources\": null"; - } + } - StringBuilder buf = new StringBuilder(); - Map<String, String> valueMap = new HashMap<>(); + StringBuilder buf = new StringBuilder(); + Map<String, String> valueMap = new HashMap<>(); - put(valueMap, "SERVICE_MODEL_NAME", service.getModelName()); - put(valueMap, "SERVICE_MODEL_UUID", service.getModelUUID()); - put(valueMap, "SERVICE_MODEL_INVARIANT_ID", service.getModelInvariantUUID()); - put(valueMap, "SERVICE_MODEL_VERSION", service.getModelVersion()); - put(valueMap, "SERVICE_TYPE", service.getServiceType()); - put(valueMap, "SERVICE_ROLE", service.getServiceRole()); - put(valueMap, "ENVIRONMENT_CONTEXT", service.getEnvironmentContext()); - put(valueMap, "WORKLOAD_CONTEXT", service.getWorkloadContext()); - put(valueMap, "RESOURCE_ORDER", service.getResourceOrder()); + put(valueMap, "SERVICE_MODEL_NAME", service.getModelName()); + put(valueMap, "SERVICE_MODEL_UUID", service.getModelUUID()); + put(valueMap, "SERVICE_MODEL_INVARIANT_ID", service.getModelInvariantUUID()); + put(valueMap, "SERVICE_MODEL_VERSION", service.getModelVersion()); + put(valueMap, "SERVICE_TYPE", service.getServiceType()); + put(valueMap, "SERVICE_ROLE", service.getServiceRole()); + put(valueMap, "ENVIRONMENT_CONTEXT", service.getEnvironmentContext()); + put(valueMap, "WORKLOAD_CONTEXT", service.getWorkloadContext()); + put(valueMap, "RESOURCE_ORDER", service.getResourceOrder()); - String subitem; - subitem = new QueryServiceVnfs(service.getVnfCustomizations()).JSON2(true, true); - valueMap.put("_SERVICEVNFS_", subitem.replaceAll(LINE_BEGINNING, "\t")); + String subitem; + subitem = new QueryServiceVnfs(service.getVnfCustomizations()).JSON2(true, true); + valueMap.put("_SERVICEVNFS_", subitem.replaceAll(LINE_BEGINNING, "\t")); - subitem = new QueryServiceNetworks(service.getNetworkCustomizations()).JSON2(true, true); - valueMap.put("_SERVICENETWORKS_", subitem.replaceAll(LINE_BEGINNING, "\t")); + subitem = new QueryServiceNetworks(service.getNetworkCustomizations()).JSON2(true, true); + valueMap.put("_SERVICENETWORKS_", subitem.replaceAll(LINE_BEGINNING, "\t")); - subitem = new QueryAllottedResourceCustomization(service.getAllottedCustomizations()).JSON2(true, true); - valueMap.put("_SERVICEALLOTTEDRESOURCES_", subitem.replaceAll(LINE_BEGINNING, "\t")); + subitem = new QueryAllottedResourceCustomization(service.getAllottedCustomizations()).JSON2(true, true); + valueMap.put("_SERVICEALLOTTEDRESOURCES_", subitem.replaceAll(LINE_BEGINNING, "\t")); buf.append(this.setTemplate(TEMPLATE, valueMap)); - return buf.toString(); - } + return buf.toString(); + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java index f7457fda4a..96ea797631 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java @@ -26,9 +26,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.xml.bind.annotation.XmlRootElement; - import org.onap.so.db.catalog.beans.NetworkResourceCustomization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,98 +34,99 @@ import org.slf4j.LoggerFactory; @XmlRootElement(name = "serviceNetworks") public class QueryServiceNetworks extends CatalogQuery { protected static Logger logger = LoggerFactory.getLogger(QueryServiceNetworks.class); - private List<NetworkResourceCustomization> serviceNetworks; - private static final String TEMPLATE = - "\t{\n"+ - "\t\t\"modelInfo\" : {\n"+ - "\t\t\t\"modelName\" : <MODEL_NAME>,\n"+ - "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ - "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ - "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ - "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+ - "\t\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n"+ - "\t},\n"+ - "\t\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n"+ - "\t\t\"networkType\" : <NETWORK_TYPE>,\n"+ - "\t\t\"networkTechnology\" : <NETWORK_TECHNOLOGY>,\n"+ - "\t\t\"resourceInput\" : <RESOURCE_INPUT>,\n"+ - "\t\t\"networkRole\" : <NETWORK_ROLE>,\n"+ - "\t\t\"networkScope\" : <NETWORK_SCOPE>\n"+ - "\t}"; + private List<NetworkResourceCustomization> serviceNetworks; + private static final String TEMPLATE = + "\t{\n" + "\t\t\"modelInfo\" : {\n" + "\t\t\t\"modelName\" : <MODEL_NAME>,\n" + + "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n" + + "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n" + + "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n" + + "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n" + + "\t\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n" + "\t},\n" + + "\t\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n" + + "\t\t\"networkType\" : <NETWORK_TYPE>,\n" + + "\t\t\"networkTechnology\" : <NETWORK_TECHNOLOGY>,\n" + + "\t\t\"resourceInput\" : <RESOURCE_INPUT>,\n" + + "\t\t\"networkRole\" : <NETWORK_ROLE>,\n" + + "\t\t\"networkScope\" : <NETWORK_SCOPE>\n" + "\t}"; - public QueryServiceNetworks() { - super(); - serviceNetworks = new ArrayList<>(); - } - - public QueryServiceNetworks(List<NetworkResourceCustomization> vlist) { - logger.debug ("QueryServiceNetworks:"); - serviceNetworks = new ArrayList<>(); - for (NetworkResourceCustomization o : vlist) { - if(logger.isDebugEnabled()) - logger.debug (o.toString()); - serviceNetworks.add(o); - } - } + public QueryServiceNetworks() { + super(); + serviceNetworks = new ArrayList<>(); + } - public List<NetworkResourceCustomization> getServiceNetworks(){ return this.serviceNetworks; } - public void setServiceNetworks(List<NetworkResourceCustomization> v) { this.serviceNetworks = v; } + public QueryServiceNetworks(List<NetworkResourceCustomization> vlist) { + logger.debug("QueryServiceNetworks:"); + serviceNetworks = new ArrayList<>(); + for (NetworkResourceCustomization o : vlist) { + if (logger.isDebugEnabled()) + logger.debug(o.toString()); + serviceNetworks.add(o); + } + } - @Override - public String toString () { - StringBuilder sb = new StringBuilder(); + public List<NetworkResourceCustomization> getServiceNetworks() { + return this.serviceNetworks; + } - boolean first = true; - int i = 1; - for (NetworkResourceCustomization o : serviceNetworks) { - sb.append(i).append("\t"); - if (!first) - sb.append("\n"); - first = false; - sb.append(o); - } - return sb.toString(); + public void setServiceNetworks(List<NetworkResourceCustomization> v) { + this.serviceNetworks = v; } - @Override - public String JSON2(boolean isArray, boolean isEmbed) { - StringBuilder sb = new StringBuilder(); - if (!isEmbed && isArray) - sb.append("{ "); - if (isArray) - sb.append("\"serviceNetworks\": ["); + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); - Map<String, String> valueMap = new HashMap<>(); - String sep = ""; - boolean first = true; + boolean first = true; + int i = 1; + for (NetworkResourceCustomization o : serviceNetworks) { + sb.append(i).append("\t"); + if (!first) + sb.append("\n"); + first = false; + sb.append(o); + } + return sb.toString(); + } + + @Override + public String JSON2(boolean isArray, boolean isEmbed) { + StringBuilder sb = new StringBuilder(); + if (!isEmbed && isArray) + sb.append("{ "); + if (isArray) + sb.append("\"serviceNetworks\": ["); - for (NetworkResourceCustomization o : serviceNetworks) { - if (first) - sb.append("\n"); - first = false; - boolean nrNull = o.getNetworkResource() == null ? true : false; - put(valueMap, "MODEL_NAME", nrNull ? null : o.getNetworkResource().getModelName()); - put(valueMap, "MODEL_UUID", nrNull ? null : o.getNetworkResource().getModelUUID()); - put(valueMap, "MODEL_INVARIANT_ID", nrNull ? null : o.getNetworkResource().getModelInvariantUUID()); - put(valueMap, "MODEL_VERSION", nrNull ? null : o.getNetworkResource().getModelVersion()); - put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); - put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName()); - put(valueMap, "TOSCA_NODE_TYPE", nrNull ? null : o.getNetworkResource().getToscaNodeType()); - put(valueMap, "NETWORK_TYPE", o.getNetworkType()); - put(valueMap, "NETWORK_ROLE", o.getNetworkRole()); - put(valueMap, "NETWORK_SCOPE", o.getNetworkScope()); - put(valueMap, "NETWORK_TECHNOLOGY", o.getNetworkTechnology()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + Map<String, String> valueMap = new HashMap<>(); + String sep = ""; + boolean first = true; + + for (NetworkResourceCustomization o : serviceNetworks) { + if (first) + sb.append("\n"); + first = false; + boolean nrNull = o.getNetworkResource() == null ? true : false; + put(valueMap, "MODEL_NAME", nrNull ? null : o.getNetworkResource().getModelName()); + put(valueMap, "MODEL_UUID", nrNull ? null : o.getNetworkResource().getModelUUID()); + put(valueMap, "MODEL_INVARIANT_ID", nrNull ? null : o.getNetworkResource().getModelInvariantUUID()); + put(valueMap, "MODEL_VERSION", nrNull ? null : o.getNetworkResource().getModelVersion()); + put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); + put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName()); + put(valueMap, "TOSCA_NODE_TYPE", nrNull ? null : o.getNetworkResource().getToscaNodeType()); + put(valueMap, "NETWORK_TYPE", o.getNetworkType()); + put(valueMap, "NETWORK_ROLE", o.getNetworkRole()); + put(valueMap, "NETWORK_SCOPE", o.getNetworkScope()); + put(valueMap, "NETWORK_TECHNOLOGY", o.getNetworkTechnology()); + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); sep = ",\n"; - } - if (!first) - sb.append("\n"); - if (isArray) - sb.append("]"); - if (!isEmbed && isArray) - sb.append("}"); - return sb.toString(); - } + } + if (!first) + sb.append("\n"); + if (isArray) + sb.append("]"); + if (!isEmbed && isArray) + sb.append("}"); + return sb.toString(); + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java index 4170047e0b..b1bdeda445 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java @@ -17,7 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - + package org.onap.so.adapters.catalogdb.catalogrest; /* should be called QueryVnfResource.java */ @@ -25,9 +25,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.xml.bind.annotation.XmlRootElement; - import org.onap.so.db.catalog.beans.VnfResourceCustomization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,105 +33,102 @@ import org.slf4j.LoggerFactory; @XmlRootElement(name = "serviceVnfs") public class QueryServiceVnfs extends CatalogQuery { protected static Logger logger = LoggerFactory.getLogger(QueryServiceVnfs.class); - - private List<VnfResourceCustomization> serviceVnfs; - private static final String TEMPLATE = - "\n"+ - "\t{ \"modelInfo\" : {\n"+ - "\t\t\"modelName\" : <MODEL_NAME>,\n"+ - "\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ - "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ - "\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ - "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+ - "\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n"+ - "\t\t},\n"+ - "\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n"+ - "\t\"nfFunction\" : <NF_FUNCTION>,\n"+ - "\t\"nfType\" : <NF_TYPE>,\n"+ - "\t\"nfRole\" : <NF_ROLE>,\n"+ - "\t\"nfNamingCode\" : <NF_NAMING_CODE>,\n"+ - "\t\"multiStageDesign\" : <MULTI_STEP_DESIGN>,\n"+ - "\t\"resourceInput\" : <RESOURCE_INPUT>,\n"+ - "<_VFMODULES_>\n" + - "\t}"; - - public QueryServiceVnfs() { - super(); - serviceVnfs = new ArrayList<>(); - } - - public QueryServiceVnfs(List<VnfResourceCustomization> vlist) { - serviceVnfs = new ArrayList<>(); - for (VnfResourceCustomization o : vlist) { - if(logger.isDebugEnabled()) - logger.debug (o.toString()); - serviceVnfs.add(o); - } - } - - public List<VnfResourceCustomization> getServiceVnfs(){ return this.serviceVnfs; } - public void setServiceVnfs(List<VnfResourceCustomization> v) { this.serviceVnfs = v; } - - @Override - public String toString () { - StringBuilder sb = new StringBuilder(); - - boolean first = true; - int i = 1; - for (VnfResourceCustomization o : serviceVnfs) { - sb.append(i).append("\t"); - if (!first) - sb.append("\n"); - first = false; - sb.append(o); - } - return sb.toString(); + + private List<VnfResourceCustomization> serviceVnfs; + private static final String TEMPLATE = "\n" + "\t{ \"modelInfo\" : {\n" + + "\t\t\"modelName\" : <MODEL_NAME>,\n" + "\t\t\"modelUuid\" : <MODEL_UUID>,\n" + + "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n" + + "\t\t\"modelVersion\" : <MODEL_VERSION>,\n" + + "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n" + + "\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n" + "\t\t},\n" + + "\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n" + + "\t\"nfFunction\" : <NF_FUNCTION>,\n" + "\t\"nfType\" : <NF_TYPE>,\n" + + "\t\"nfRole\" : <NF_ROLE>,\n" + "\t\"nfNamingCode\" : <NF_NAMING_CODE>,\n" + + "\t\"multiStageDesign\" : <MULTI_STEP_DESIGN>,\n" + + "\t\"resourceInput\" : <RESOURCE_INPUT>,\n" + "<_VFMODULES_>\n" + "\t}"; + + public QueryServiceVnfs() { + super(); + serviceVnfs = new ArrayList<>(); } - @Override - public String JSON2(boolean isArray, boolean isEmbed) { - StringBuilder sb = new StringBuilder(); - if (!isEmbed && isArray) - sb.append("{ "); - if (isArray) - sb.append("\"serviceVnfs\": ["); - Map<String, String> valueMap = new HashMap<>(); - String sep = ""; - boolean first = true; - - for (VnfResourceCustomization o : serviceVnfs) { - if (first) - sb.append("\n"); - first = false; - - boolean vrNull = o.getVnfResources() == null ? true : false; - - put(valueMap, "MODEL_NAME", vrNull ? null : o.getVnfResources().getModelName()); - put(valueMap, "MODEL_UUID", vrNull ? null : o.getVnfResources().getModelUUID()); - put(valueMap, "MODEL_INVARIANT_ID", vrNull ? null : o.getVnfResources().getModelInvariantId()); - put(valueMap, "MODEL_VERSION", vrNull ? null : o.getVnfResources().getModelVersion()); - put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); - put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName()); - put(valueMap, "TOSCA_NODE_TYPE", vrNull ? null : o.getVnfResources().getToscaNodeType()); - put(valueMap, "NF_FUNCTION", o.getNfFunction()); - put(valueMap, "NF_TYPE", o.getNfType()); - put(valueMap, "NF_ROLE", o.getNfRole()); - put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode()); - put(valueMap, "MULTI_STEP_DESIGN", o.getMultiStageDesign()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); - - String subitem = new QueryVfModule(vrNull ? null : o.getVfModuleCustomizations()).JSON2(true, true); - valueMap.put("_VFMODULES_", subitem.replaceAll("(?m)^", "\t\t")); + public QueryServiceVnfs(List<VnfResourceCustomization> vlist) { + serviceVnfs = new ArrayList<>(); + for (VnfResourceCustomization o : vlist) { + if (logger.isDebugEnabled()) + logger.debug(o.toString()); + serviceVnfs.add(o); + } + } + + public List<VnfResourceCustomization> getServiceVnfs() { + return this.serviceVnfs; + } + + public void setServiceVnfs(List<VnfResourceCustomization> v) { + this.serviceVnfs = v; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + boolean first = true; + int i = 1; + for (VnfResourceCustomization o : serviceVnfs) { + sb.append(i).append("\t"); + if (!first) + sb.append("\n"); + first = false; + sb.append(o); + } + return sb.toString(); + } + + @Override + public String JSON2(boolean isArray, boolean isEmbed) { + StringBuilder sb = new StringBuilder(); + if (!isEmbed && isArray) + sb.append("{ "); + if (isArray) + sb.append("\"serviceVnfs\": ["); + Map<String, String> valueMap = new HashMap<>(); + String sep = ""; + boolean first = true; + + for (VnfResourceCustomization o : serviceVnfs) { + if (first) + sb.append("\n"); + first = false; + + boolean vrNull = o.getVnfResources() == null ? true : false; + + put(valueMap, "MODEL_NAME", vrNull ? null : o.getVnfResources().getModelName()); + put(valueMap, "MODEL_UUID", vrNull ? null : o.getVnfResources().getModelUUID()); + put(valueMap, "MODEL_INVARIANT_ID", vrNull ? null : o.getVnfResources().getModelInvariantId()); + put(valueMap, "MODEL_VERSION", vrNull ? null : o.getVnfResources().getModelVersion()); + put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); + put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName()); + put(valueMap, "TOSCA_NODE_TYPE", vrNull ? null : o.getVnfResources().getToscaNodeType()); + put(valueMap, "NF_FUNCTION", o.getNfFunction()); + put(valueMap, "NF_TYPE", o.getNfType()); + put(valueMap, "NF_ROLE", o.getNfRole()); + put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode()); + put(valueMap, "MULTI_STEP_DESIGN", o.getMultiStageDesign()); + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + + String subitem = new QueryVfModule(vrNull ? null : o.getVfModuleCustomizations()).JSON2(true, true); + valueMap.put("_VFMODULES_", subitem.replaceAll("(?m)^", "\t\t")); sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); sep = ",\n"; - } - if (!first) - sb.append("\n"); - if (isArray) - sb.append("]"); - if (!isEmbed && isArray) - sb.append("}"); - return sb.toString(); - } + } + if (!first) + sb.append("\n"); + if (isArray) + sb.append("]"); + if (!isEmbed && isArray) + sb.append("}"); + return sb.toString(); + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVfModule.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVfModule.java index 3680c59dca..1dec9cecae 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVfModule.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVfModule.java @@ -17,114 +17,112 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - + package org.onap.so.adapters.catalogdb.catalogrest; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.xml.bind.annotation.XmlRootElement; - import org.onap.so.db.catalog.beans.HeatEnvironment; import org.onap.so.db.catalog.beans.VfModuleCustomization; @XmlRootElement(name = "vfModules") public class QueryVfModule extends CatalogQuery { - private List<VfModuleCustomization> vfModules; - private static final String TEMPLATE = - "\t{\n"+ - "\t\t\"modelInfo\" : { \n"+ - "\t\t\t\"modelName\" : <MODEL_NAME>,\n"+ - "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ - "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ - "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ - "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>\n"+ - "\t\t},"+ - "\t\t\"isBase\" : <IS_BASE>,\n"+ - "\t\t\"vfModuleLabel\" : <VF_MODULE_LABEL>,\n"+ - "\t\t\"initialCount\" : <INITIAL_COUNT>,\n"+ - "\t\t\"hasVolumeGroup\" : <HAS_VOLUME_GROUP>\n"+ - "\t}"; + private List<VfModuleCustomization> vfModules; + private static final String TEMPLATE = "\t{\n" + "\t\t\"modelInfo\" : { \n" + + "\t\t\t\"modelName\" : <MODEL_NAME>,\n" + + "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n" + + "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n" + + "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n" + + "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>\n" + "\t\t}," + + "\t\t\"isBase\" : <IS_BASE>,\n" + "\t\t\"vfModuleLabel\" : <VF_MODULE_LABEL>,\n" + + "\t\t\"initialCount\" : <INITIAL_COUNT>,\n" + + "\t\t\"hasVolumeGroup\" : <HAS_VOLUME_GROUP>\n" + "\t}"; + + public QueryVfModule() { + super(); + vfModules = new ArrayList<>(); + } - public QueryVfModule() { - super(); - vfModules = new ArrayList<>(); - } - - public QueryVfModule(List<VfModuleCustomization> vlist) { - vfModules = new ArrayList<>(); - if (vlist != null) { - for (VfModuleCustomization o : vlist) { - if(logger.isDebugEnabled()) - logger.debug (o.toString()); - vfModules.add(o); - } - } - } + public QueryVfModule(List<VfModuleCustomization> vlist) { + vfModules = new ArrayList<>(); + if (vlist != null) { + for (VfModuleCustomization o : vlist) { + if (logger.isDebugEnabled()) + logger.debug(o.toString()); + vfModules.add(o); + } + } + } - public List<VfModuleCustomization> getVfModule(){ return this.vfModules; } - public void setVfModule(List<VfModuleCustomization> v) { this.vfModules = v; } + public List<VfModuleCustomization> getVfModule() { + return this.vfModules; + } - @Override - public String toString () { - StringBuilder sb = new StringBuilder(); + public void setVfModule(List<VfModuleCustomization> v) { + this.vfModules = v; + } - boolean first = true; - int i = 1; - for (VfModuleCustomization o : vfModules) { - sb.append(i).append("\t"); - if (!first) - sb.append("\n"); - first = false; - sb.append(o); - } - return sb.toString(); + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + boolean first = true; + int i = 1; + for (VfModuleCustomization o : vfModules) { + sb.append(i).append("\t"); + if (!first) + sb.append("\n"); + first = false; + sb.append(o); + } + return sb.toString(); } - @Override - public String JSON2(boolean isArray, boolean isEmbed) { - StringBuilder sb = new StringBuilder(); - if (!isEmbed && isArray) - sb.append("{ "); - if (isArray) - sb.append("\"vfModules\": ["); - Map<String, String> valueMap = new HashMap<>(); - String sep = ""; - boolean first = true; + @Override + public String JSON2(boolean isArray, boolean isEmbed) { + StringBuilder sb = new StringBuilder(); + if (!isEmbed && isArray) + sb.append("{ "); + if (isArray) + sb.append("\"vfModules\": ["); + Map<String, String> valueMap = new HashMap<>(); + String sep = ""; + boolean first = true; - for (VfModuleCustomization o : vfModules) { - if (first) - sb.append("\n"); - first = false; + for (VfModuleCustomization o : vfModules) { + if (first) + sb.append("\n"); + first = false; - boolean vfNull = o.getVfModule() == null ? true : false; - boolean hasVolumeGroup = false; - HeatEnvironment envt = o.getVolumeHeatEnv(); - if (envt != null) { - hasVolumeGroup = true; - } + boolean vfNull = o.getVfModule() == null ? true : false; + boolean hasVolumeGroup = false; + HeatEnvironment envt = o.getVolumeHeatEnv(); + if (envt != null) { + hasVolumeGroup = true; + } - put(valueMap, "MODEL_NAME", vfNull ? null : o.getVfModule().getModelName()); - put(valueMap, "MODEL_UUID", vfNull ? null : o.getVfModule().getModelUUID()); - put(valueMap, "MODEL_INVARIANT_ID", vfNull ? null : o.getVfModule().getModelInvariantUUID()); - put(valueMap, "MODEL_VERSION", vfNull ? null : o.getVfModule().getModelVersion()); - put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); - put(valueMap, "IS_BASE", vfNull ? false : o.getVfModule().getIsBase() ? true : false); - put(valueMap, "VF_MODULE_LABEL", o.getLabel()); - put(valueMap, "INITIAL_COUNT", o.getInitialCount()); - put(valueMap, "HAS_VOLUME_GROUP", new Boolean(hasVolumeGroup)); + put(valueMap, "MODEL_NAME", vfNull ? null : o.getVfModule().getModelName()); + put(valueMap, "MODEL_UUID", vfNull ? null : o.getVfModule().getModelUUID()); + put(valueMap, "MODEL_INVARIANT_ID", vfNull ? null : o.getVfModule().getModelInvariantUUID()); + put(valueMap, "MODEL_VERSION", vfNull ? null : o.getVfModule().getModelVersion()); + put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); + put(valueMap, "IS_BASE", vfNull ? false : o.getVfModule().getIsBase() ? true : false); + put(valueMap, "VF_MODULE_LABEL", o.getLabel()); + put(valueMap, "INITIAL_COUNT", o.getInitialCount()); + put(valueMap, "HAS_VOLUME_GROUP", new Boolean(hasVolumeGroup)); sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); sep = ",\n"; - } - if (!first) - sb.append("\n"); - if (isArray) - sb.append("]"); - if (!isEmbed && isArray) - sb.append("}"); - return sb.toString(); - } + } + if (!first) + sb.append("\n"); + if (isArray) + sb.append("]"); + if (!isEmbed && isArray) + sb.append("}"); + return sb.toString(); + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java index 5009dce020..6cc53e6ec9 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java @@ -26,7 +26,6 @@ package org.onap.so.adapters.catalogdb.rest; import java.util.ArrayList; import java.util.List; - import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -36,7 +35,6 @@ import javax.ws.rs.core.GenericEntity; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - import org.apache.http.HttpStatus; import org.onap.so.adapters.catalogdb.catalogrest.CatalogQuery; import org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException; @@ -125,176 +123,159 @@ public class CatalogDbAdapterRest { private static final String NO_MATCHING_PARAMETERS = "no matching parameters"; public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) { - return Response - .status(respStatus) - .entity(qryResp.toJsonString(version, isArray)) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) - .build(); + return Response.status(respStatus).entity(qryResp.toJsonString(version, isArray)) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build(); } @GET @Path("vnfResources/{vnfModelCustomizationUuid}") - @Transactional( readOnly = true) - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public Response serviceVnfs ( - @PathParam("version") String version, - @PathParam("vnfModelCustomizationUuid") String vnfUuid - ) { - return serviceVnfsImpl (version, !IS_ARRAY, vnfUuid, null, null, null, null); + @Transactional(readOnly = true) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response serviceVnfs(@PathParam("version") String version, + @PathParam("vnfModelCustomizationUuid") String vnfUuid) { + return serviceVnfsImpl(version, !IS_ARRAY, vnfUuid, null, null, null, null); } @GET @Path("serviceVnfs") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Transactional( readOnly = true) - public Response serviceVnfs( - @PathParam("version") String version, - @QueryParam("vnfModelCustomizationUuid") String vnfUuid, - @QueryParam("serviceModelUuid") String smUuid, - @QueryParam("serviceModelInvariantUuid") String smiUuid, - @QueryParam("serviceModelVersion") String smVer, - @QueryParam("serviceModelName") String smName - ) { - return serviceVnfsImpl (version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName); + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) + public Response serviceVnfs(@PathParam("version") String version, + @QueryParam("vnfModelCustomizationUuid") String vnfUuid, @QueryParam("serviceModelUuid") String smUuid, + @QueryParam("serviceModelInvariantUuid") String smiUuid, @QueryParam("serviceModelVersion") String smVer, + @QueryParam("serviceModelName") String smName) { + return serviceVnfsImpl(version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName); } - public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String serviceModelUUID, String smiUuid, String smVer, String smName) { + public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String serviceModelUUID, + String smiUuid, String smVer, String smName) { QueryServiceVnfs qryResp = null; - int respStatus = HttpStatus.SC_OK; + int respStatus = HttpStatus.SC_OK; List<VnfResourceCustomization> ret = new ArrayList<>(); Service service = null; try { - if (vnfUuid != null && !"".equals(vnfUuid)) - ret = vnfCustomizationRepo.findByModelCustomizationUUID(vnfUuid); - else if (serviceModelUUID != null && !"".equals(serviceModelUUID)) + if (vnfUuid != null && !"".equals(vnfUuid)) + ret = vnfCustomizationRepo.findByModelCustomizationUUID(vnfUuid); + else if (serviceModelUUID != null && !"".equals(serviceModelUUID)) service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(serviceModelUUID); - else if (smiUuid != null && !"".equals(smiUuid)) - if (smVer != null && !"".equals(smVer)) - service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer,smiUuid); - else + else if (smiUuid != null && !"".equals(smiUuid)) + if (smVer != null && !"".equals(smVer)) + service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, smiUuid); + else service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(smiUuid); else if (smName != null && !"".equals(smName)) { - if (smVer != null && !"".equals(smVer)) + if (smVer != null && !"".equals(smVer)) service = serviceRepo.findByModelNameAndModelVersion(smName, smVer); - else - service = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(smName); - } - else { - throw(new Exception(NO_MATCHING_PARAMETERS)); + else + service = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(smName); + } else { + throw (new Exception(NO_MATCHING_PARAMETERS)); } if (service == null && ret.isEmpty()) { respStatus = HttpStatus.SC_NOT_FOUND; qryResp = new QueryServiceVnfs(); - }else if( service == null && !ret.isEmpty()){ - qryResp = new QueryServiceVnfs(ret); + } else if (service == null && !ret.isEmpty()) { + qryResp = new QueryServiceVnfs(ret); } else if (service != null) { - qryResp = new QueryServiceVnfs(service.getVnfCustomizations()); + qryResp = new QueryServiceVnfs(service.getVnfCustomizations()); } - logger.debug ("serviceVnfs qryResp= {}", qryResp); + logger.debug("serviceVnfs qryResp= {}", qryResp); return respond(version, respStatus, isArray, qryResp); } catch (Exception e) { logger.error("Exception - queryServiceVnfs", e); - CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); - return Response - .status(HttpStatus.SC_INTERNAL_SERVER_ERROR) - .entity(new GenericEntity<CatalogQueryException>(excResp) {}) - .build(); + CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), + CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); + return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) + .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build(); } } @GET @Path("networkResources/{networkModelCustomizationUuid}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Transactional( readOnly = true) - public Response serviceNetworks ( - @PathParam("version") String version, - @PathParam("networkModelCustomizationUuid") String nUuid - ) { - return serviceNetworksImpl (version, !IS_ARRAY, nUuid, null, null, null, null); + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) + public Response serviceNetworks(@PathParam("version") String version, + @PathParam("networkModelCustomizationUuid") String nUuid) { + return serviceNetworksImpl(version, !IS_ARRAY, nUuid, null, null, null, null); } @GET @Path("serviceNetworks") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Transactional( readOnly = true) - public Response serviceNetworks ( - @PathParam("version") String version, + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) + public Response serviceNetworks(@PathParam("version") String version, @QueryParam("networkModelCustomizationUuid") String networkModelCustomizationUuid, - @QueryParam("networkType") String networkType, - @QueryParam("networkModelName") String networkModelName, + @QueryParam("networkType") String networkType, @QueryParam("networkModelName") String networkModelName, @QueryParam("serviceModelUuid") String serviceModelUuid, @QueryParam("serviceModelInvariantUuid") String serviceModelInvariantUuid, @QueryParam("serviceModelVersion") String serviceModelVersion, - @QueryParam("networkModelVersion") String networkModelVersion - ) { + @QueryParam("networkModelVersion") String networkModelVersion) { if (networkModelName != null && !"".equals(networkModelName)) { networkType = networkModelName; } - return serviceNetworksImpl (version, IS_ARRAY, networkModelCustomizationUuid, networkType, serviceModelUuid, serviceModelInvariantUuid, serviceModelVersion); + return serviceNetworksImpl(version, IS_ARRAY, networkModelCustomizationUuid, networkType, serviceModelUuid, + serviceModelInvariantUuid, serviceModelVersion); } - public Response serviceNetworksImpl (String version, boolean isArray, String networkModelCustomizationUuid, String networkType, String serviceModelUuid, String serviceModelInvariantUuid, String serviceModelVersion) { + public Response serviceNetworksImpl(String version, boolean isArray, String networkModelCustomizationUuid, + String networkType, String serviceModelUuid, String serviceModelInvariantUuid, String serviceModelVersion) { QueryServiceNetworks qryResp; int respStatus = HttpStatus.SC_OK; String uuid = ""; List<NetworkResourceCustomization> ret = new ArrayList<>(); Service service = null; - try{ + try { if (networkModelCustomizationUuid != null && !"".equals(networkModelCustomizationUuid)) { - uuid = networkModelCustomizationUuid; + uuid = networkModelCustomizationUuid; ret = networkCustomizationRepo.findByModelCustomizationUUID(networkModelCustomizationUuid); - }else if (networkType != null && !"".equals(networkType)) { - uuid = networkType; - NetworkResource networkResources = networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType); - if(networkResources != null) - ret=networkResources.getNetworkResourceCustomization(); - } - else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) { + } else if (networkType != null && !"".equals(networkType)) { + uuid = networkType; + NetworkResource networkResources = + networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType); + if (networkResources != null) + ret = networkResources.getNetworkResourceCustomization(); + } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) { uuid = serviceModelInvariantUuid; - if (serviceModelVersion != null && !"".equals(serviceModelVersion)) { + if (serviceModelVersion != null && !"".equals(serviceModelVersion)) { service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(serviceModelVersion, uuid); - } - else { + } else { service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid); } - }else if (serviceModelUuid != null && !"".equals(serviceModelUuid)) { - uuid = serviceModelUuid; + } else if (serviceModelUuid != null && !"".equals(serviceModelUuid)) { + uuid = serviceModelUuid; service = serviceRepo.findOneByModelUUID(serviceModelUuid); - } - else { - throw(new Exception(NO_MATCHING_PARAMETERS)); + } else { + throw (new Exception(NO_MATCHING_PARAMETERS)); } - if(service != null) + if (service != null) ret = service.getNetworkCustomizations(); if (ret == null || ret.isEmpty()) { - logger.debug ("serviceNetworks not found"); + logger.debug("serviceNetworks not found"); respStatus = HttpStatus.SC_NOT_FOUND; qryResp = new QueryServiceNetworks(); - } else { + } else { qryResp = new QueryServiceNetworks(ret); - logger.debug ("serviceNetworks found qryResp= {}", qryResp); + logger.debug("serviceNetworks found qryResp= {}", qryResp); } return respond(version, respStatus, isArray, qryResp); } catch (Exception e) { - logger.error ("Exception - queryServiceNetworks", e); - CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); - return Response - .status(HttpStatus.SC_INTERNAL_SERVER_ERROR) - .entity(new GenericEntity<CatalogQueryException>(excResp) {}) - .build(); + logger.error("Exception - queryServiceNetworks", e); + CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), + CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); + return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) + .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build(); } } @GET @Path("serviceResources") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Transactional(readOnly = true) - public Response serviceResources( - @PathParam("version") String version, + public Response serviceResources(@PathParam("version") String version, @QueryParam("serviceModelUuid") String modelUUID, @QueryParam("serviceModelInvariantUuid") String modelInvariantUUID, @QueryParam("serviceModelVersion") String modelVersion) { @@ -303,11 +284,11 @@ public class CatalogDbAdapterRest { String uuid = ""; ServiceMacroHolder ret = new ServiceMacroHolder(); - try{ + try { if (modelUUID != null && !"".equals(modelUUID)) { uuid = modelUUID; - logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: {}" , uuid); - Service serv =serviceRepo.findOneByModelUUID(uuid); + logger.debug("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: {}", uuid); + Service serv = serviceRepo.findOneByModelUUID(uuid); if (serv != null) { ret.setNetworkResourceCustomizations(new ArrayList(serv.getNetworkCustomizations())); @@ -315,163 +296,149 @@ public class CatalogDbAdapterRest { ret.setAllottedResourceCustomizations(new ArrayList(serv.getAllottedCustomizations())); } ret.setService(serv); - } - else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) { + } else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) { uuid = modelInvariantUUID; if (modelVersion != null && !"".equals(modelVersion)) { - logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: {} serviceModelVersion: {}",uuid, modelVersion); + logger.debug( + "Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: {} serviceModelVersion: {}", + uuid, modelVersion); Service serv = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(modelVersion, uuid); ret.setService(serv); - } - else { - logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: {}" , uuid); + } else { + logger.debug( + "Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: {}", + uuid); Service serv = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid); ret.setService(serv); } - } - else { - throw(new Exception(NO_MATCHING_PARAMETERS)); + } else { + throw (new Exception(NO_MATCHING_PARAMETERS)); } if (ret.getService() == null) { - logger.debug ("serviceMacroHolder not found"); + logger.debug("serviceMacroHolder not found"); respStatus = HttpStatus.SC_NOT_FOUND; qryResp = new QueryServiceMacroHolder(); } else { qryResp = new QueryServiceMacroHolder(ret); - logger.debug ("serviceMacroHolder qryResp= {}", qryResp); + logger.debug("serviceMacroHolder qryResp= {}", qryResp); } return respond(version, respStatus, IS_ARRAY, qryResp); } catch (Exception e) { - logger.error ("Exception - queryServiceMacroHolder", e); - CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); - return Response - .status(HttpStatus.SC_INTERNAL_SERVER_ERROR) - .entity(new GenericEntity<CatalogQueryException>(excResp){} ) - .build(); + logger.error("Exception - queryServiceMacroHolder", e); + CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), + CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); + return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) + .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build(); } } @GET @Path("allottedResources/{arModelCustomizationUuid}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Transactional( readOnly = true) - public Response serviceAllottedResources ( - @PathParam("version") String version, - @PathParam("arModelCustomizationUuid") String aUuid - ) { + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) + public Response serviceAllottedResources(@PathParam("version") String version, + @PathParam("arModelCustomizationUuid") String aUuid) { return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null); } @GET @Path("serviceAllottedResources") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Transactional( readOnly = true) - public Response serviceAllottedResources( - @PathParam("version") String version, - @QueryParam("serviceModelUuid") String smUuid, - @QueryParam("serviceModelInvariantUuid") String smiUuid, - @QueryParam("serviceModelVersion") String smVer, - @QueryParam("arModelCustomizationUuid") String aUuid - ) { + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) + public Response serviceAllottedResources(@PathParam("version") String version, + @QueryParam("serviceModelUuid") String smUuid, @QueryParam("serviceModelInvariantUuid") String smiUuid, + @QueryParam("serviceModelVersion") String smVer, @QueryParam("arModelCustomizationUuid") String aUuid) { return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer); } - public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid, String serviceModelInvariantUuid, String smVer) { + public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid, + String serviceModelInvariantUuid, String smVer) { QueryAllottedResourceCustomization qryResp; int respStatus = HttpStatus.SC_OK; String uuid = ""; List<AllottedResourceCustomization> ret = new ArrayList<>(); Service service = null; - try{ + try { if (smUuid != null && !"".equals(smUuid)) { - uuid = smUuid; - service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(uuid); - } - else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) { + uuid = smUuid; + service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(uuid); + } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) { uuid = serviceModelInvariantUuid; - if (smVer != null && !"".equals(smVer)) { + if (smVer != null && !"".equals(smVer)) { service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(smVer, uuid); - } - else { + } else { service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid); } - } - else if (aUuid != null && !"".equals(aUuid)) { - uuid = aUuid; + } else if (aUuid != null && !"".equals(aUuid)) { + uuid = aUuid; ret = allottedCustomizationRepo.findByModelCustomizationUUID(uuid); - } - else { - throw(new Exception(NO_MATCHING_PARAMETERS)); + } else { + throw (new Exception(NO_MATCHING_PARAMETERS)); } - if(service != null) - ret=service.getAllottedCustomizations(); + if (service != null) + ret = service.getAllottedCustomizations(); if (ret == null || ret.isEmpty()) { - logger.debug ("AllottedResourceCustomization not found"); + logger.debug("AllottedResourceCustomization not found"); respStatus = HttpStatus.SC_NOT_FOUND; qryResp = new QueryAllottedResourceCustomization(); - } else { + } else { qryResp = new QueryAllottedResourceCustomization(ret); - logger.debug ("AllottedResourceCustomization qryResp= {}", qryResp); - } + logger.debug("AllottedResourceCustomization qryResp= {}", qryResp); + } return respond(version, respStatus, isArray, qryResp); } catch (Exception e) { - logger.error ("Exception - queryAllottedResourceCustomization", e); - CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); - return Response - .status(HttpStatus.SC_INTERNAL_SERVER_ERROR) - .entity(new GenericEntity<CatalogQueryException>(excResp) {}) - .build(); + logger.error("Exception - queryAllottedResourceCustomization", e); + CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), + CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); + return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) + .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build(); } } @GET @Path("vfModules") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Transactional( readOnly = true) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) { QueryVfModule qryResp; int respStatus = HttpStatus.SC_OK; - List<VfModuleCustomization> ret = null; - try{ - if(vfModuleModelName != null && !"".equals(vfModuleModelName)){ + List<VfModuleCustomization> ret = null; + try { + if (vfModuleModelName != null && !"".equals(vfModuleModelName)) { VfModule vfModule = vfModuleRepo.findFirstByModelNameOrderByModelVersionDesc(vfModuleModelName); - if(vfModule != null) - ret = vfModule.getVfModuleCustomization(); - }else{ - throw(new Exception(NO_MATCHING_PARAMETERS)); + if (vfModule != null) + ret = vfModule.getVfModuleCustomization(); + } else { + throw (new Exception(NO_MATCHING_PARAMETERS)); } - if(ret == null || ret.isEmpty()){ - logger.debug ("vfModules not found"); + if (ret == null || ret.isEmpty()) { + logger.debug("vfModules not found"); respStatus = HttpStatus.SC_NOT_FOUND; qryResp = new QueryVfModule(); - }else{ - qryResp = new QueryVfModule(ret); - if(logger.isDebugEnabled()) - logger.debug ("vfModules tojsonstring is: {}", qryResp.JSON2(false, false)); - } - return Response - .status(respStatus) - .entity(qryResp.JSON2(false, false)) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) - .build(); - }catch(Exception e){ - logger.error ("Exception during query VfModules by vfModuleModuleName: ", e); - CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); - return Response - .status(HttpStatus.SC_INTERNAL_SERVER_ERROR) - .entity(new GenericEntity<CatalogQueryException>(excResp) {}) - .build(); + } else { + qryResp = new QueryVfModule(ret); + if (logger.isDebugEnabled()) + logger.debug("vfModules tojsonstring is: {}", qryResp.JSON2(false, false)); + } + return Response.status(respStatus).entity(qryResp.JSON2(false, false)) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build(); + } catch (Exception e) { + logger.error("Exception during query VfModules by vfModuleModuleName: ", e); + CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), + CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); + return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) + .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build(); } } + /** - * Get the tosca csar info from catalog - * <br> + * Get the tosca csar info from catalog <br> * * @param smUuid service model uuid * @return the tosca csar information of the serivce. @@ -479,13 +446,13 @@ public class CatalogDbAdapterRest { */ @GET @Path("serviceToscaCsar") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) { int respStatus = HttpStatus.SC_OK; String entity = ""; try { if (smUuid != null && !"".equals(smUuid)) { - logger.debug("Query Csar by service model uuid: {}",smUuid); + logger.debug("Query Csar by service model uuid: {}", smUuid); Service service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(smUuid); @@ -504,26 +471,19 @@ public class CatalogDbAdapterRest { } else { throw (new Exception("Incoming parameter is null or blank")); } - return Response - .status(respStatus) - .entity(entity) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) - .build(); + return Response.status(respStatus).entity(entity) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build(); } catch (Exception e) { logger.error("Exception during query csar by service model uuid: ", e); CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); - return Response - .status(HttpStatus.SC_INTERNAL_SERVER_ERROR) - .entity(new GenericEntity<CatalogQueryException>(excResp) { - }) - .build(); + return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) + .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build(); } } /** - * Get the resource recipe info from catalog - * <br> + * Get the resource recipe info from catalog <br> * * @param rmUuid resource model uuid * @return the recipe information of the resource. @@ -531,19 +491,21 @@ public class CatalogDbAdapterRest { */ @GET @Path("resourceRecipe") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid, @QueryParam("action") String action) { + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid, + @QueryParam("action") String action) { int respStatus = HttpStatus.SC_OK; String entity = ""; try { if (rmUuid != null && !"".equals(rmUuid)) { logger.debug("Query recipe by resource model uuid: {}", rmUuid); - //check vnf and network and ar, the resource could be any resource. + // check vnf and network and ar, the resource could be any resource. Recipe recipe = null; VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid); if (vnf != null) { - recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action, vnf.getModelVersion()); + recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action, + vnf.getModelVersion()); // for network service fetch the default recipe if (recipe == null && vnf.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) { @@ -555,8 +517,9 @@ public class CatalogDbAdapterRest { if (null == recipe) { NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid); - if(nResource != null) { - recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(), action, nResource.getModelVersion()); + if (nResource != null) { + recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(), + action, nResource.getModelVersion()); // for network fetch the default recipe if (recipe == null) { @@ -568,7 +531,8 @@ public class CatalogDbAdapterRest { if (null == recipe) { AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid); if (arResource != null) { - recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action, arResource.getModelVersion()); + recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action, + arResource.getModelVersion()); } } if (recipe != null) { @@ -580,20 +544,14 @@ public class CatalogDbAdapterRest { } else { throw new Exception("Incoming parameter is null or blank"); } - return Response - .status(respStatus) - .entity(entity) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) - .build(); + return Response.status(respStatus).entity(entity) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build(); } catch (Exception e) { logger.error("Exception during query recipe by resource model uuid: ", e); CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); - return Response - .status(HttpStatus.SC_INTERNAL_SERVER_ERROR) - .entity(new GenericEntity<CatalogQueryException>(excResp) { - }) - .build(); + return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR) + .entity(new GenericEntity<CatalogQueryException>(excResp) {}).build(); } } } |