diff options
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services')
5 files changed, 286 insertions, 0 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/pom.xml new file mode 100644 index 0000000000..a5979798d2 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/pom.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.openecomp.sdc</groupId> + <artifactId>application-config-rest</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>application-config-rest-services</artifactId> + <!--packaging>pom</packaging--> + + <dependencies> + + <dependency> + <groupId>io.swagger</groupId> + <artifactId>swagger-annotations</artifactId> + <version>1.5.3</version> + </dependency> + <dependency> + <groupId>javax.ws.rs</groupId> + <artifactId>javax.ws.rs-api</artifactId> + <version>${ws.rs.version}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.framework.version}</version> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>1</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-application-config-manager</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>application-config-rest-types</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-common-rest</artifactId> + <version>${project.version}</version> + </dependency> + <!-- CXF --> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxrs</artifactId> + <version>${cxf.version}</version> + </dependency> + </dependencies> + + +</project>
\ No newline at end of file diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/ApplicationConfiguration.java b/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/ApplicationConfiguration.java new file mode 100644 index 0000000000..df743a6a93 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/ApplicationConfiguration.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.applicationconfig.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; +import org.openecomp.sdcrests.applicationconfiguration.types.ConfigurationDataDto; +import org.springframework.validation.annotation.Validated; + +import java.io.InputStream; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + + +@Path("/v1.0/application-configuration") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +@Api(value = "Application Configuration") +@Validated +public interface ApplicationConfiguration { + + @POST + @Path("/") + @Consumes(MediaType.MULTIPART_FORM_DATA) + @ApiOperation(value = "Insert JSON schema into application config table") + Response insertToTable(@QueryParam("namespace") String namespace, @QueryParam("key") String key, + @Multipart("value") InputStream fileContainingSchema); + + + @GET + @Path("/{namespace}/{key}") + @ApiOperation(value = "Get JSON schema by namespace and key", + response = ConfigurationDataDto.class) + Response getFromTable(@PathParam("namespace") String namespace, @PathParam("key") String key); + + + @GET + @Path("/{namespace}") + @ApiOperation(value = "Get List of keys and values by namespace", + responseContainer = "List") + Response getListOfConfigurationByNamespaceFromTable(@PathParam("namespace") String namespace); + +} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/mapping/MapApplicationConfigEntityToApplicationConfigDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/mapping/MapApplicationConfigEntityToApplicationConfigDto.java new file mode 100644 index 0000000000..4d43e37769 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/mapping/MapApplicationConfigEntityToApplicationConfigDto.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.applicationconfig.rest.mapping; + +import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity; +import org.openecomp.sdcrests.applicationconfiguration.types.ApplicationConfigDto; +import org.openecomp.sdcrests.mapping.MappingBase; + +public class MapApplicationConfigEntityToApplicationConfigDto + extends MappingBase<ApplicationConfigEntity, ApplicationConfigDto> { + @Override + public void doMapping(ApplicationConfigEntity source, ApplicationConfigDto target) { + target.setKey(source.getKey()); + target.setValue(source.getValue()); + } +} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/mapping/MapConfigurationDataToConfigurationDataDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/mapping/MapConfigurationDataToConfigurationDataDto.java new file mode 100644 index 0000000000..6865c676ec --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/mapping/MapConfigurationDataToConfigurationDataDto.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.applicationconfig.rest.mapping; + +import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData; +import org.openecomp.sdcrests.applicationconfiguration.types.ConfigurationDataDto; +import org.openecomp.sdcrests.mapping.MappingBase; + +public class MapConfigurationDataToConfigurationDataDto + extends MappingBase<ConfigurationData, ConfigurationDataDto> { + @Override + public void doMapping(ConfigurationData source, ConfigurationDataDto target) { + target.setValue(source.getValue()); + target.setTimeStamp(source.getTimeStamp()); + } +} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/services/ApplicationConfigurationImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/services/ApplicationConfigurationImpl.java new file mode 100644 index 0000000000..81f7251fdc --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/application-config-rest/application-config-rest-services/src/main/java/org/openecomp/sdcrests/applicationconfig/rest/services/ApplicationConfigurationImpl.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.applicationconfig.rest.services; + +import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity; +import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.sdc.applicationconfig.ApplicationConfigManager; +import org.openecomp.sdcrests.applicationconfig.rest.ApplicationConfiguration; +import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapApplicationConfigEntityToApplicationConfigDto; +import org.openecomp.sdcrests.applicationconfig.rest.mapping.MapConfigurationDataToConfigurationDataDto; +import org.openecomp.sdcrests.applicationconfiguration.types.ApplicationConfigDto; +import org.openecomp.sdcrests.applicationconfiguration.types.ConfigurationDataDto; +import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import java.io.InputStream; +import java.util.Collection; +import javax.inject.Named; + +import javax.ws.rs.core.Response; + +@Named +@Service("applicationConfiguration") +@Scope(value = "prototype") +public class ApplicationConfigurationImpl implements ApplicationConfiguration { + + @Autowired + private ApplicationConfigManager applicationConfigManager; + + + @Override + public Response insertToTable(String namespace, String key, InputStream fileContainingSchema) { + String value = new String(FileUtils.toByteArray(fileContainingSchema)); + + applicationConfigManager.insertIntoTable(namespace, key, value); + + return Response.ok().build(); + } + + @Override + public Response getFromTable(String namespace, String key) { + ConfigurationData value = applicationConfigManager.getFromTable(namespace, key); + ConfigurationDataDto valueDto = new MapConfigurationDataToConfigurationDataDto() + .applyMapping(value, ConfigurationDataDto.class); + + return Response.ok(valueDto).build(); + } + + @Override + public Response getListOfConfigurationByNamespaceFromTable(String namespace) { + Collection<ApplicationConfigEntity> applicationConfigEntities = + applicationConfigManager.getListOfConfigurationByNamespace(namespace); + GenericCollectionWrapper<ApplicationConfigDto> applicationConfigWrapper = + new GenericCollectionWrapper<>(); + MapApplicationConfigEntityToApplicationConfigDto mapper = + new MapApplicationConfigEntityToApplicationConfigDto(); + + for (ApplicationConfigEntity applicationConfigEntity : applicationConfigEntities) { + applicationConfigWrapper + .add(mapper.applyMapping(applicationConfigEntity, ApplicationConfigDto.class)); + } + + return Response.ok(applicationConfigWrapper).build(); + } +} |