Repository: incubator-unomi Updated Branches: refs/heads/feature-DMF-1343 b954ad4af -> 5d8f1be5a
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-core/src/main/java/org/apache/unomi/router/core/route/ProfileImportSourceToKafkaRouteBuilder.java ---------------------------------------------------------------------- diff --git a/router/router-core/src/main/java/org/apache/unomi/router/core/route/ProfileImportSourceToKafkaRouteBuilder.java b/router/router-core/src/main/java/org/apache/unomi/router/core/route/ProfileImportSourceToKafkaRouteBuilder.java deleted file mode 100644 index 382b69d..0000000 --- a/router/router-core/src/main/java/org/apache/unomi/router/core/route/ProfileImportSourceToKafkaRouteBuilder.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.apache.unomi.router.core.route; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jackson.JacksonDataFormat; -import org.apache.camel.component.kafka.KafkaComponent; -import org.apache.camel.component.kafka.KafkaConfiguration; -import org.apache.camel.component.kafka.KafkaEndpoint; -import org.apache.commons.lang3.StringUtils; -import org.apache.unomi.router.api.ImportConfiguration; -import org.apache.unomi.router.core.processor.LineSplitProcessor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.Map; - -/** - * Created by amidani on 26/04/2017. - */ - -public class ProfileImportSourceToKafkaRouteBuilder extends RouteBuilder { - - private static final Logger logger = LoggerFactory.getLogger(ProfileImportSourceToKafkaRouteBuilder.class.getName()); - - private List<ImportConfiguration> importConfigurationList; - private JacksonDataFormat jacksonDataFormat; - private String kafkaHost; - private String kafkaPort; - private String kafkaImportTopic; - private String kafkaImportGroupId; - - public ProfileImportSourceToKafkaRouteBuilder(Map<String, String> kafkaProps) { - kafkaHost = kafkaProps.get("kafkaHost"); - kafkaPort = kafkaProps.get("kafkaPort"); - kafkaImportTopic = kafkaProps.get("kafkaImportTopic"); - kafkaImportGroupId = kafkaProps.get("kafkaImportGroupId"); - } - - @Override - public void configure() throws Exception { - //Prepare Kafka Deposit - StringBuilder kafkaUri = new StringBuilder("kafka:"); - kafkaUri.append(kafkaHost).append(":").append(kafkaPort).append("?topic=").append(kafkaImportTopic); - if(StringUtils.isNotBlank(kafkaImportGroupId)) { - kafkaUri.append("&groupId="+ kafkaImportGroupId); - } - - KafkaConfiguration kafkaConfiguration = new KafkaConfiguration(); - kafkaConfiguration.setBrokers(kafkaHost+":"+kafkaPort); - kafkaConfiguration.setTopic(kafkaImportTopic); - kafkaConfiguration.setGroupId(kafkaImportGroupId); - KafkaEndpoint endpoint = new KafkaEndpoint(kafkaUri.toString(), new KafkaComponent(this.getContext())); - endpoint.setConfiguration(kafkaConfiguration); - - //Loop on multiple import configuration - for(ImportConfiguration importConfiguration : importConfigurationList) { - if(importConfiguration.getProperties().size() > 0 && - StringUtils.isNotEmpty((String) importConfiguration.getProperties().get("source"))) { - //Prepare Split Processor - LineSplitProcessor lineSplitProcessor = new LineSplitProcessor(); - lineSplitProcessor.setFieldsMapping((Map<String, Integer>) importConfiguration.getProperties().get("mapping")); - lineSplitProcessor.setOverwriteExistingProfiles(importConfiguration.isOverwriteExistingProfiles()); - lineSplitProcessor.setPropertiesToOverwrite(importConfiguration.getPropertiesToOverwrite()); - lineSplitProcessor.setMergingProperty(importConfiguration.getMergingProperty()); - - from((String) importConfiguration.getProperties().get("source")) - .routeId(importConfiguration.getItemId())// This allow identification of the route for manual start/stop - .autoStartup(importConfiguration.isActive())// Auto-start if the import configuration is set active - .split(bodyAs(String.class).tokenize("\n")) - .process(lineSplitProcessor) - .to("log:org.apache.unomi.router?level=INFO") - .marshal(jacksonDataFormat) - .convertBodyTo(String.class) - .to(endpoint); - } - } - } - - public void setImportConfigurationList(List<ImportConfiguration> importConfigurationList) { - this.importConfigurationList = importConfigurationList; - } - - public void setJacksonDataFormat(JacksonDataFormat jacksonDataFormat) { - this.jacksonDataFormat = jacksonDataFormat; - } - - public void setKafkaHost(String kafkaHost) { - this.kafkaHost = kafkaHost; - } - - public void setKafkaPort(String kafkaPort) { - this.kafkaPort = kafkaPort; - } - - public void setKafkaImportTopic(String kafkaImportTopic) { - this.kafkaImportTopic = kafkaImportTopic; - } - - public void setKafkaImportGroupId(String kafkaImportGroupId) { - this.kafkaImportGroupId = kafkaImportGroupId; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/router/router-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/router/router-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index ff29755..0000000 --- a/router/router-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,94 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You 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. - --> -<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" - xmlns:camel="http://camel.apache.org/schema/blueprint" - xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd - http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd - http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> - - <cm:property-placeholder persistent-id="org.apache.unomi.router" update-strategy="reload"> - <cm:default-properties> - <cm:property name="kafka.host" value="localhost"/> - <cm:property name="kafka.port" value="9092"/> - <cm:property name="kafka.import.topic" value="camel-deposit"/> - <cm:property name="kafka.import.groupId" value="unomi-import-group"/> - <cm:property name="import.oneshot.uploadDir" value="/tmp/oneshot_import_configs/"/> - </cm:default-properties> - </cm:property-placeholder> - - <bean id="unomiStorageProcessor" class="org.apache.unomi.router.core.processor.UnomiStorageProcessor"> - <property name="profileImportService" ref="profileImportService"/> - </bean> - - <bean id="importConfigByFileNameProcessor" class="org.apache.unomi.router.core.processor.ImportConfigByFileNameProcessor"> - <property name="importConfigurationService" ref="importConfigurationService"/> - </bean> - - <bean id="jacksonDataFormat" class="org.apache.camel.component.jackson.JacksonDataFormat"> - <property name="unmarshalType" value="org.apache.unomi.router.api.ProfileToImport"/> - </bean> - - <bean id="jacksonDataFormatImportConfig" class="org.apache.camel.model.dataformat.JsonDataFormat"> - <property name="unmarshalType" value="org.apache.unomi.router.api.ImportConfiguration"/> - <property name="library" value="Jackson"/> - </bean> - - <bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer" - init-method="register" - destroy-method="unregister"> - <property name="alias" value="/importConfigAdmin"/> - <property name="httpService" ref="httpService"/> - <property name="servlet" ref="camelServlet"/> - </bean> - - <bean id="camelServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/> - - - <bean id="camelContext" class="org.apache.unomi.router.core.context.ProfileImportCamelContext" - init-method="initCamelContext" destroy-method="preDestroy"> - <property name="kafkaProps"> - <map> - <entry key="kafkaHost" value="${kafka.host}"/> - <entry key="kafkaPort" value="${kafka.port}"/> - <entry key="kafkaImportTopic" value="${kafka.import.topic}"/> - <entry key="kafkaImportGroupId" value="${kafka.import.groupId}"/> - </map> - </property> - <property name="uploadDir" value="${import.oneshot.uploadDir}"/> - <property name="unomiStorageProcessor" ref="unomiStorageProcessor"/> - <property name="importConfigByFileNameProcessor" ref="importConfigByFileNameProcessor"/> - <property name="importConfigurationService" ref="importConfigurationService"/> - <property name="jacksonDataFormat" ref="jacksonDataFormat"/> - <property name="bundleContext" ref="blueprintBundleContext"/> - </bean> - - <camelContext id="httpEndpoint" xmlns="http://camel.apache.org/schema/blueprint"> - <routeBuilder ref="profileImportConfigUpdateRouteBuilder" /> - </camelContext> - - <bean id="profileImportConfigUpdateRouteBuilder" class="org.apache.unomi.router.core.route.ProfileImportConfigUpdateRouteBuilder"> - <property name="profileImportCamelContext" ref="camelContext"/> - </bean> - - <reference id="httpService" interface="org.osgi.service.http.HttpService"/> - <reference id="profileImportService" interface="org.apache.unomi.router.api.services.ProfileImportService"/> - <reference id="importConfigurationService" interface="org.apache.unomi.router.api.services.ImportConfigurationService"/> - -</blueprint> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-core/src/main/resources/org.apache.unomi.router.cfg ---------------------------------------------------------------------- diff --git a/router/router-core/src/main/resources/org.apache.unomi.router.cfg b/router/router-core/src/main/resources/org.apache.unomi.router.cfg deleted file mode 100644 index b11d983..0000000 --- a/router/router-core/src/main/resources/org.apache.unomi.router.cfg +++ /dev/null @@ -1,23 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# -kafka.host=localhost -kafka.port=9092 -kafka.import.topic=camel-deposit -kafka.import.groupId=unomi-import-group - -#Import One Shot upload directory -import.oneshot.uploadDir=/tmp/unomi_oneshot_import_configs/ \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-karaf-feature/pom.xml ---------------------------------------------------------------------- diff --git a/router/router-karaf-feature/pom.xml b/router/router-karaf-feature/pom.xml deleted file mode 100644 index 8a8e62c..0000000 --- a/router/router-karaf-feature/pom.xml +++ /dev/null @@ -1,157 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You 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. - --> -<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"> - <parent> - <artifactId>unomi-router</artifactId> - <groupId>org.apache.unomi</groupId> - <version>1.2.0-incubating-dmf_1343-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>unomi-router-karaf-feature</artifactId> - <name>Apache Unomi :: Extensions :: Router :: Apache Karaf Feature</name> - <description>Apache Karaf feature for the Apache Unomi Context Server extension</description> - <packaging>feature</packaging> - <dependencies> - <dependency> - <groupId>org.apache.servicemix.bundles</groupId> - <artifactId>org.apache.servicemix.bundles.jsch</artifactId> - <version>0.1.54_1</version> - </dependency> - <dependency> - <groupId>commons-net</groupId> - <artifactId>commons-net</artifactId> - <version>3.5</version> - </dependency> - <dependency> - <groupId>org.apache.kafka</groupId> - <artifactId>kafka-clients</artifactId> - <version>0.10.1.0</version> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-core</artifactId> - <version>${camel.version}</version> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-blueprint</artifactId> - <version>${camel.version}</version> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-jackson</artifactId> - <version>${camel.version}</version> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-http-common</artifactId> - <version>${camel.version}</version> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-servlet</artifactId> - <version>${camel.version}</version> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-ftp</artifactId> - <version>${camel.version}</version> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-stream</artifactId> - <version>${camel.version}</version> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-kafka</artifactId> - <version>${camel.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-rs-security-cors</artifactId> - <version>${cxf.version}</version> - </dependency> - - <!-- UNOMI ROUTER Modules Dependencies --> - <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-persistence-spi</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-router-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-router-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-router-service</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-router-rest</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient-osgi</artifactId> - <type>bundle</type> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpcore-osgi</artifactId> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.karaf.tooling</groupId> - <artifactId>karaf-maven-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <includeTransitiveDependency>false</includeTransitiveDependency> - </configuration> - </plugin> - </plugins> - </pluginManagement> - - <plugins> - <plugin> - <groupId>org.apache.karaf.tooling</groupId> - <artifactId>karaf-maven-plugin</artifactId> - <configuration> - <startLevel>90</startLevel> - </configuration> - </plugin> - </plugins> - </build> -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-rest/pom.xml ---------------------------------------------------------------------- diff --git a/router/router-rest/pom.xml b/router/router-rest/pom.xml deleted file mode 100644 index e39e919..0000000 --- a/router/router-rest/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You 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. - --> -<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"> - <parent> - <artifactId>unomi-router</artifactId> - <groupId>org.apache.unomi</groupId> - <version>1.2.0-incubating-dmf_1343-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>unomi-router-rest</artifactId> - <name>Apache Unomi :: Extensions :: Router :: REST API</name> - <description>Router REST API</description> - <packaging>bundle</packaging> - - <dependencies> - <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-router-api</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-api</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>javax.ws.rs</groupId> - <artifactId>javax.ws.rs-api</artifactId> - <version>2.0.1</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-rs-security-cors</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient-osgi</artifactId> - <type>bundle</type> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpcore-osgi</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <scope>provided</scope> - </dependency> - </dependencies> - -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java ---------------------------------------------------------------------- diff --git a/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java b/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java deleted file mode 100644 index e81930a..0000000 --- a/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.apache.unomi.router.rest; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.cxf.jaxrs.ext.multipart.Multipart; -import org.apache.cxf.jaxrs.ext.multipart.Attachment; -import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.unomi.router.api.ImportConfiguration; -import org.apache.unomi.router.api.services.ImportConfigurationService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.jws.WebMethod; -import javax.jws.WebService; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.List; - -/** - * A JAX-RS endpoint to manage {@link org.apache.unomi.router.api.ImportConfiguration}s. - */ -@WebService -@CrossOriginResourceSharing( - allowAllOrigins = true, - allowCredentials = true -) -public class ImportConfigurationServiceEndPoint { - - private static final Logger logger = LoggerFactory.getLogger(ImportConfigurationServiceEndPoint.class.getName()); - - private ImportConfigurationService importConfigurationService; - private String uploadDir; - - public ImportConfigurationServiceEndPoint () { - logger.info("Initializing import configuration service endpoint..."); - } - - @WebMethod(exclude = true) - public void setImportConfigurationService(ImportConfigurationService importConfigurationService) { - this.importConfigurationService = importConfigurationService; - } - - @WebMethod(exclude = true) - public void setUploadDir(String uploadDir) { - this.uploadDir = uploadDir; - } - - /** - * Retrieves all the import configurations. - * - * @return all the import configurations. - */ - @GET - @Path("/") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - public List<ImportConfiguration> getImportConfigurations() { - return importConfigurationService.getImportConfigurations(); - } - - /** - * Retrieves an import configuration by id. - * - * @return the import configuration that matches the given id. - */ - @GET - @Path("/{configId}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - public ImportConfiguration getImportConfiguration(@PathParam("configId") String configId) { - return importConfigurationService.load(configId); - } - - /** - * Delete an import configuration by id. - * - * @return the deleted import configuration. - */ - @DELETE - @Path("/{configId}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - public void deleteImportConfiguration(@PathParam("configId") String configId) { - importConfigurationService.delete(configId); - } - - - - /** - * Save the given import configuration. - * - * @return the import configuration saved. - */ - @POST - @Path("/") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - public ImportConfiguration saveImportConfiguration(ImportConfiguration importConfiguration) { - ImportConfiguration importConfigSaved = importConfigurationService.save(importConfiguration); - CloseableHttpClient httpClient = HttpClients.createDefault(); - try { - HttpPut httpPut = new HttpPut("http://localhost:8181/importConfigAdmin/"); - StringEntity input = new StringEntity(new ObjectMapper().writeValueAsString(importConfigSaved)); - input.setContentType(MediaType.APPLICATION_JSON); - httpPut.setEntity(input); - - HttpResponse response = httpClient.execute(httpPut); - - if (response.getStatusLine().getStatusCode() != 200) { - throw new RuntimeException("Failed : HTTP error code : " - + response.getStatusLine().getStatusCode()); - } - } catch (IOException e) { - logger.warn("Unable to update Camel route [{}]", importConfiguration.getItemId()); - } - return importConfigSaved; - } - - /** - * Save/Update the given import configuration. - * Prepare the file to be processed with Camel routes - * @return OK / NOK Http Code. - */ - @POST - @Path("/oneshot") - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(MediaType.APPLICATION_JSON) - public Response processOneshotImportConfigurationCSV(@Multipart(value = "importConfigId") String importConfigId, @Multipart(value = "file") Attachment file) { - try { - java.nio.file.Path path = Paths.get(uploadDir+importConfigId+".csv"); - Files.deleteIfExists(path); - InputStream in = file.getObject(InputStream.class); - - Files.copy(in, path); - - } catch (IOException e) { - e.printStackTrace(); - return Response.serverError().build(); - } - return Response.ok().build(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/router/router-rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/router/router-rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index a5cf1be..0000000 --- a/router/router-rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,72 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You 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. - --> - -<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" - xmlns:cxf="http://cxf.apache.org/blueprint/core" xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs" - xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd - http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd - http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd - http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd"> - <cm:property-placeholder persistent-id="org.apache.unomi.router" update-strategy="reload"> - <cm:default-properties> - <cm:property name="import.oneshot.uploadDir" value="/tmp/oneshot_import_configs/"/> - </cm:default-properties> - </cm:property-placeholder> - - <cxf:bus id="cxsServiceBus"> - <cxf:features> - <cxf:logging/> - </cxf:features> - </cxf:bus> - - <bean id="cors-filter" class="org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter"/> - <bean id="jacksonMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/> - <bean id="json-provider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"> - <argument index="0" ref="jacksonMapper" type="com.fasterxml.jackson.databind.ObjectMapper"/> - </bean> - <bean id="jaas-filter" class="org.apache.cxf.jaxrs.security.JAASAuthenticationFilter"> - <!-- Name of the JAAS Context --> - <property name="contextName" value="karaf"/> - <!-- Hint to the filter on how to have Principals representing users and roles separated - while initializing a SecurityContext --> - <property name="rolePrefix" value="ROLE_"/> - <property name="realmName" value="cxs"/> - </bean> - - <jaxrs:server address="/importConfiguration" id="restImportConfigurationService"> - <jaxrs:providers> - <ref component-id="json-provider"/> - <ref component-id="cors-filter"/> - <ref component-id="jaas-filter"/> - </jaxrs:providers> - - <jaxrs:serviceBeans> - <ref component-id="importConfigurationServiceEndPoint"/> - </jaxrs:serviceBeans> - </jaxrs:server> - - <reference id="importConfigurationService" interface="org.apache.unomi.router.api.services.ImportConfigurationService"/> - - <bean id="importConfigurationServiceEndPoint" class="org.apache.unomi.router.rest.ImportConfigurationServiceEndPoint"> - <property name="importConfigurationService" ref="importConfigurationService"/> - <property name="uploadDir" value="${import.oneshot.uploadDir}"/> - </bean> - -</blueprint> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-service/pom.xml ---------------------------------------------------------------------- diff --git a/router/router-service/pom.xml b/router/router-service/pom.xml deleted file mode 100644 index 0aed70e..0000000 --- a/router/router-service/pom.xml +++ /dev/null @@ -1,104 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You 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. - --> -<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"> - <parent> - <artifactId>unomi-router</artifactId> - <groupId>org.apache.unomi</groupId> - <version>1.2.0-incubating-dmf_1343-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>unomi-router-service</artifactId> - <name>Apache Unomi :: Extensions :: Router :: Services</name> - <description>Router Services</description> - <packaging>bundle</packaging> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> - <Import-Package> - sun.misc;resolution:=optional, - * - </Import-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - - <dependencies> - <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-api</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-router-api</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.apache.unomi</groupId> - <artifactId>unomi-persistence-spi</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - </dependency> - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - </dependency> - - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>javax.servlet-api</artifactId> - <scope>provided</scope> - </dependency> - - </dependencies> - - -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-service/src/main/java/org/apache/unomi/router/services/ImportConfigurationServiceImpl.java ---------------------------------------------------------------------- diff --git a/router/router-service/src/main/java/org/apache/unomi/router/services/ImportConfigurationServiceImpl.java b/router/router-service/src/main/java/org/apache/unomi/router/services/ImportConfigurationServiceImpl.java deleted file mode 100644 index a4f6131..0000000 --- a/router/router-service/src/main/java/org/apache/unomi/router/services/ImportConfigurationServiceImpl.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.unomi.router.services; - -import org.apache.unomi.router.api.ImportConfiguration; -import org.apache.unomi.router.api.services.ImportConfigurationService; -import org.apache.unomi.persistence.spi.PersistenceService; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; -import org.osgi.framework.SynchronousBundleListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.UUID; - -/** - * Created by amidani on 28/04/2017. - */ -public class ImportConfigurationServiceImpl implements ImportConfigurationService,SynchronousBundleListener { - - private static final Logger logger = LoggerFactory.getLogger(ImportConfigurationServiceImpl.class.getName()); - - private BundleContext bundleContext; - private PersistenceService persistenceService; - - public ImportConfigurationServiceImpl() { - logger.info("Initializing import configuration service..."); - } - - public void setBundleContext(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } - - public void setPersistenceService(PersistenceService persistenceService) { - this.persistenceService = persistenceService; - } - - public void postConstruct() { - logger.debug("postConstruct {" + bundleContext.getBundle() + "}"); - - processBundleStartup(bundleContext); - for (Bundle bundle : bundleContext.getBundles()) { - if (bundle.getBundleContext() != null) { - processBundleStartup(bundle.getBundleContext()); - } - } - bundleContext.addBundleListener(this); - logger.info("Import configuration service initialized."); - } - - public void preDestroy() { - bundleContext.removeBundleListener(this); - logger.info("Import configuration service shutdown."); - } - - private void processBundleStartup(BundleContext bundleContext) { - if (bundleContext == null) { - return; - } - } - - private void processBundleStop(BundleContext bundleContext) { - } - - - @Override - public List<ImportConfiguration> getImportConfigurations() { - return persistenceService.getAllItems(ImportConfiguration.class); - } - - @Override - public ImportConfiguration load(String configId) { - return persistenceService.load(configId, ImportConfiguration.class); - } - - @Override - public ImportConfiguration save(ImportConfiguration importConfiguration) { - if (importConfiguration.getItemId() == null) { - importConfiguration.setItemId(UUID.randomUUID().toString()); - } - if(persistenceService.save(importConfiguration)) { - - } - - return persistenceService.load(importConfiguration.getItemId(), ImportConfiguration.class); - } - - @Override - public void delete(String configId) { - persistenceService.remove(configId, ImportConfiguration.class); - } - - @Override - public void bundleChanged(BundleEvent bundleEvent) { - - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-service/src/main/java/org/apache/unomi/router/services/ProfileImportServiceImpl.java ---------------------------------------------------------------------- diff --git a/router/router-service/src/main/java/org/apache/unomi/router/services/ProfileImportServiceImpl.java b/router/router-service/src/main/java/org/apache/unomi/router/services/ProfileImportServiceImpl.java deleted file mode 100644 index 8097953..0000000 --- a/router/router-service/src/main/java/org/apache/unomi/router/services/ProfileImportServiceImpl.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.apache.unomi.router.services; - -import org.apache.commons.beanutils.BeanUtils; -import org.apache.unomi.api.Profile; -import org.apache.unomi.api.services.EventListenerService; -import org.apache.unomi.persistence.spi.PersistenceService; -import org.apache.unomi.router.api.ProfileToImport; -import org.apache.unomi.router.api.services.ProfileImportService; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; -import org.osgi.framework.SynchronousBundleListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.InvocationTargetException; -import java.util.List; - -/** - * Created by amidani on 18/05/2017. - */ -public class ProfileImportServiceImpl implements ProfileImportService, SynchronousBundleListener { - - private static final Logger logger = LoggerFactory.getLogger(ProfileImportServiceImpl.class.getName()); - - private PersistenceService persistenceService; - - private BundleContext bundleContext; - - public void setPersistenceService(PersistenceService persistenceService) { - this.persistenceService = persistenceService; - } - - public void setBundleContext(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } - - public void postConstruct() { - logger.debug("postConstruct {" + bundleContext.getBundle() + "}"); - - processBundleStartup(bundleContext); - for (Bundle bundle : bundleContext.getBundles()) { - if (bundle.getBundleContext() != null) { - processBundleStartup(bundle.getBundleContext()); - } - } - bundleContext.addBundleListener(this); - logger.info("Import configuration service initialized."); - } - - public void preDestroy() { - bundleContext.removeBundleListener(this); - logger.info("Import configuration service shutdown."); - } - - private void processBundleStartup(BundleContext bundleContext) { - if (bundleContext == null) { - return; - } - } - - private void processBundleStop(BundleContext bundleContext) { - } - - - public boolean saveMergeDeleteImportedProfile(ProfileToImport profileToImport) throws InvocationTargetException, IllegalAccessException { - logger.info("Importing profile: {}, {}", profileToImport.getProperties().get("firstName"), profileToImport.getProperties().get("lastName")); - Profile existingProfile = new Profile(); - List<Profile> existingProfiles = persistenceService.query("properties."+profileToImport.getMergingProperty(), (String)profileToImport.getProperties().get(profileToImport.getMergingProperty()), null, Profile.class); - logger.info("Query existing profile with mergingProperty: {}", profileToImport.getMergingProperty()); - logger.info("Found: {}", existingProfiles.size()); - - //Profile already exist, and import config allow to overwrite profiles - if(existingProfiles.size() == 1) { - existingProfile = existingProfiles.get(0); - if(profileToImport.isProfileToDelete()) { - logger.info("Profile is to delete!"); - persistenceService.remove(existingProfile.getItemId(), Profile.class); - return true; - } - List<String> propertiesToOverwrite = profileToImport.getPropertiesToOverwrite(); - if(profileToImport.isOverwriteExistingProfiles() && propertiesToOverwrite!=null && propertiesToOverwrite.size() > 0) { // We overwrite only properties marked to overwrite - logger.info("Properties to overwrite: {}", propertiesToOverwrite); - for(String propName : propertiesToOverwrite) { - existingProfile.getProperties().put(propName, profileToImport.getProperties().get(propName)); - } - } else { //If no property is marked to overwrite we replace the whole properties map - logger.info("Overwrite all properties"); - existingProfile.setProperties(profileToImport.getProperties()); - } - } else if(existingProfiles.size() == 0) { - logger.info("New profile to add..."); - BeanUtils.copyProperties(existingProfile, profileToImport); - } else { - logger.warn("{} occurences found for profile with {} = {}. Profile import is skipped", existingProfiles.size(), - profileToImport.getMergingProperty(), profileToImport.getProperties().get("firstName")); - } - logger.info("-------------------------------------"); - return persistenceService.save(existingProfile); - } - - @Override - public void bundleChanged(BundleEvent bundleEvent) { - - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5d8f1be5/router/router-service/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/router/router-service/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/router/router-service/src/main/resources/OSGI-INF/blueprint/blueprint.xml deleted file mode 100644 index 61200f2..0000000 --- a/router/router-service/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You 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. - --> - -<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> - - <reference id="persistenceService" interface="org.apache.unomi.persistence.spi.PersistenceService"/> - - <bean id="importConfigurationServiceImpl" class="org.apache.unomi.router.services.ImportConfigurationServiceImpl" - init-method="postConstruct" destroy-method="preDestroy"> - <property name="persistenceService" ref="persistenceService"/> - <property name="bundleContext" ref="blueprintBundleContext"/> - </bean> - <service id="importConfigurationService" ref="importConfigurationServiceImpl" auto-export="interfaces"/> - - <bean id="profileImportServiceImpl" class="org.apache.unomi.router.services.ProfileImportServiceImpl" - init-method="postConstruct" destroy-method="preDestroy"> - <property name="persistenceService" ref="persistenceService"/> - <property name="bundleContext" ref="blueprintBundleContext"/> - </bean> - <service id="profileImportService" ref="profileImportServiceImpl" auto-export="interfaces"/> - -</blueprint>