Skip to content
Snippets Groups Projects
Commit c7abfb65 authored by Rodríguez Ortega, Alejandro's avatar Rodríguez Ortega, Alejandro
Browse files

First Commit

parents
Branches
No related tags found
No related merge requests found
HELP.md
target/
mvnw
mvnw.cmd
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
/*
* Copyright 2007-present the original author or authors.
*
* 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
*
* https://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.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
File added
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
module gdsfg {
exports urbanite.prestojdbc;
exports urbanite.trafficmongopresto;
exports com.tecnalia.urbanite.storage;
exports com.tecnalia.urbanite.storage.transport.crowdflowobserved;
exports com.tecnalia.urbanite.storage.DB.Mongo;
exports com.tecnalia.urbanite.storage.transport.trafficflowobserved;
requires java.logging;
requires java.sql;
requires org.apache.logging.log4j;
}
\ No newline at end of file
FROM maven:3.6.0-jdk-8-slim AS builder
WORKDIR /home/app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src src/
RUN mvn clean package
FROM openjdk:8-slim
WORKDIR /root
COPY --from=builder /home/app/target/anonymize.jar /anonymize.jar
ENV DATA_STORAGE_URL=http://exporter:8080
EXPOSE 80
CMD ["java","-jar","/anonymize.jar"]
\ No newline at end of file
# Data Storage and Retrieval Component
Microservice for inserting and retrieving data from the databases.
## Table of Contents
1. [Clone](#clone)
2. [Push](#push)
1. [Build](#build)
1. [Docker](#docker)
1. [Configuration](#configuration)
1. [Environment](#environment)
1. [API Reference](#api-reference)
1. [License](#license)
## Clone
This project has a git submodule called 'shared'. Because of this, it is necessary to download the code including submodules.
```bash
$ git clone --recurse-submodules <repo>
```
Once downloaded:
```bash
$ cd shared
$ mvn install
```
## Push
Note that if you update the library 'shared', another project makes use of it, so you should update the commit of the other api project called 'open-data-retrieval'.
## Build
Requirements:
* Docker
## Docker
Build docker image:
```bash
$ docker build -t urbanite/datastorage .
```
Run docker image:
```bash
$ docker run -it -p 80:80 urbanite/datastorage
```
## Configuration
### Environment
| Variable| Description | Default Value |
| :--- | :--- | :--- |
| `MONGO_HOST` | The IP of the host where MongoDB is installed. | `mongodb` |
| `MONGO_PORT` | The port where MongoDB is listening. | `27017` |
| `MONGO_DBNAME` | The name of the MongoDB Database to insert/retrive data. | `urbanite` |
e.g.
```bash
$ docker run -it -p 80:80 -e MONGO_HOST=172.26.41.138 -e MONGO_PORT=27018 urbanite/datastorage
```
## API Reference
When the component is deployed, the API reference is accessible from
http://\<server\>/data/swagger-ui/index.html?configUrl=/data/v3/api-docs/swagger-config
## License
[Apache License, Version 2.0](LICENSE.md)
pom.xml 0 → 100644
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.tecnalia.urbanite</groupId>
<artifactId>Anonymize</artifactId>
<version>1.3.1</version>
<name>anonymize</name>
<description>URBANITE Anonymize Component</description>
<properties>
<java.version>1.8</java.version>
<log4j2.version>2.17.0</log4j2.version> <!-- https://spring.io/blog/2021/12/10/log4j2-vulnerability-and-spring-boot -->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Open API -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.32</version>
</dependency>
<!-- JSON -->
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.7</version>
<type>jar</type>
</dependency>
<!-- Jenna -->
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<version>3.17.0</version>
<type>pom</type>
</dependency>
<!-- Mongo -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.activation/activation -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>${start-class}</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.tecnalia.urbanite.storage.DataStorageApplication</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/*
* Copyright (c) 2022 TECNALIA RESEARCH & INNOVATION.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of Affero General Public License (AGPL) version 3
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.en.html
*
* Contributors:
*
* Gonzalo Lazaro, Jose Manuel Rio, Alejandro Rodriguez, Sonia Bilbao from Tecnalia
*
* Initially developed in the context of URBANITE EU project
* www.urbanite-project.eu
*/
package com.tecnalia.urbanite.anonymize;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.annotation.Bean;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.servers.Server;
//import io.swagger.v3.oas.models.info.Contact;
//import io.swagger.v3.oas.models.info.License;
//import io.swagger.v3.oas.models.ExternalDocumentation;
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
public class AnonymizeApplication {
public static void main(String[] args) {
SpringApplication.run(AnonymizeApplication.class, args);
}
@Bean
public OpenAPI customOpenAPI(@Value("${application-description}") String appDesciption, @Value("${application-version}") String appVersion) {
return new OpenAPI()
.addServersItem(new Server().url("/data/"))
.info(new Info()
.title("Anonymize API")
.version(appVersion)
.description(appDesciption)
//.contact(new Contact().email("info@tecnalia.com").name("Tecnalia").url("tecnalia.com"))
//.termsOfService("http://swagger.io/terms/")
//.license(new License().name("Apache 2.0").url("http://springdoc.org"))
)
//.externalDocs(new ExternalDocumentation().description("Data Model Explanation").url("/data/datamodel.html"))
;
}
}
/*
* Copyright (c) 2022 TECNALIA RESEARCH & INNOVATION.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of Affero General Public License (AGPL) version 3
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.en.html
*
* Contributors:
*
* Gonzalo Lazaro, Jose Manuel Rio, Alejandro Rodriguez, Sonia Bilbao from Tecnalia
*
* Initially developed in the context of URBANITE EU project
* www.urbanite-project.eu
*/
package com.tecnalia.urbanite.anonymize;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
@RestController
@Tag(name = "Anonymize", description = "Operations to Anonymize Data")
public class AnonymizerAPI {
@RequestMapping(method = RequestMethod.POST, value = "/anonymize/{user}")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successful operation."),
@ApiResponse(responseCode = "400", description = "Bad request.")})
@Operation(summary = "Anonimize user", description = "Change name of user for hash.")
public ResponseEntity<String> anonymizeUser(@PathVariable int user ) throws Exception {
try {
boolean respuesta = true;
if (respuesta ) {
return new ResponseEntity<>("User anonymizied successfully !!", HttpStatus.OK);
} else {
return new ResponseEntity<>("User not anonymizied", HttpStatus.INTERNAL_SERVER_ERROR);
}
} catch (Exception e) {
return new ResponseEntity<>("Error while anonymizig:" + user + ". Please try again !! " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
application-description=@project.description@
application-version=@project.version@
logging.level.org.springframework.boot.autoconfigure=ERROR
server.servlet.context-path=/data
server.port=80
logging.level.com.tecnalia.urbanite.storage=DEBUG
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment