Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nbittich committed Apr 27, 2021
0 parents commit ab40fba
Show file tree
Hide file tree
Showing 20 changed files with 748 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
HELP.md
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/

mvnw*
.mvn/


test/data/**

Scratch.java

.DS_STORE
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM maven:3.6.3-amazoncorretto-15
LABEL maintainer="[email protected]"

WORKDIR /app

COPY pom.xml .

RUN mvn -B dependency:resolve-plugins dependency:resolve

COPY ./src ./src

RUN mvn package -DskipTests
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Local Decisions as Linked Open Data in Flanders

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# [MU-JAVA]

Java helpers to handle RDF/Sparql & mu stack
140 changes: 140 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?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.3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>mu.semte.ch</groupId>
<artifactId>mu-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>mu-java</name>
<licenses>
<license>
<name>MIT</name>
</license>
</licenses>
<developers>
<developer>
<name>Nordine Bittich</name>
<email>[email protected]</email>
<organization>REDPENCIL</organization>
<organizationUrl>https://redpencil.io/</organizationUrl>
<url>https://github.com/lblod/mu-java</url>
<roles>
<role>Developer</role>
</roles>
</developer>
</developers>
<properties>
<java.version>15</java.version>
<jena.version>3.17.0</jena.version>
<guava.version>29.0-jre</guava.version>
<commons-text.version>1.9</commons-text.version>
<poi.version>5.0.0</poi.version>
</properties>
<scm>
<connection>
scm:git:[email protected]:lblod/mu-java.git
</connection>
<tag>1.0.0</tag>
</scm>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>${jena.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>${jena.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-rdfconnection</artifactId>
<version>${jena.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
20 changes: 20 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -e # fail script on error

releaseVersion=$1
nextVersion=$2-SNAPSHOT

if [[ -z "$1" || -z "$2" ]]
then
echo "version mut be provided"
exit -1;
fi

echo "release" $releaseVersion ", next" $nextVersion

mvn --batch-mode -Dtag=$releaseVersion release:prepare \
-DreleaseVersion=$releaseVersion \
-DdevelopmentVersion=$nextVersion

mvn release:clean
git pull
5 changes: 5 additions & 0 deletions src/main/java/mu/semte/ch/lib/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package mu.semte.ch.lib;

public interface Constants {
String HEADER_MU_AUTH_SUDO = "mu-auth-sudo";
}
78 changes: 78 additions & 0 deletions src/main/java/mu/semte/ch/lib/config/CoreConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package mu.semte.ch.lib.config;

import lombok.extern.slf4j.Slf4j;
import mu.semte.ch.lib.Constants;
import mu.semte.ch.lib.handler.DefaultExceptionHandler;
import mu.semte.ch.lib.utils.SparqlClient;
import mu.semte.ch.lib.utils.SparqlQueryStore;
import org.apache.commons.io.IOUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.Resource;
import org.springframework.scheduling.annotation.EnableAsync;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.github.jsonldjava.shaded.com.google.common.collect.Maps.immutableEntry;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.io.FilenameUtils.removeExtension;
import static org.apache.commons.text.CaseUtils.toCamelCase;

@Configuration
@Import(DefaultExceptionHandler.class)
@EnableAsync
@Slf4j
public class CoreConfig {

@Value("classpath:sparql/*.sparql")
private Resource[] queries;

@Value("${sparql.endpoint}")
private String sparqlUrl;

@Bean
public SparqlQueryStore sparqlQueryLoader() {
log.info("Adding {} queries to the store", queries.length);

var queriesMap = Arrays.stream(queries)
.map(r -> {
try {
var key = toCamelCase(removeExtension(r.getFilename()), false, '-');
return immutableEntry(key, IOUtils.toString(r.getInputStream(), UTF_8));
} catch (IOException e) {
throw new RuntimeException(e);
}
})
.peek(e -> log.info("query {} added to the store", e.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
return queriesMap::get;
}

@Bean
@Autowired
public SparqlClient defaultSudoSparqlClient(CloseableHttpClient closeableHttpClient) {
return SparqlClient.builder()
.url(sparqlUrl)
.httpClient(closeableHttpClient)
.build();
}

@Bean(destroyMethod = "close")
public CloseableHttpClient buildHttpClient() {
return HttpClients.custom()
.setDefaultHeaders(List.of(new BasicHeader(Constants.HEADER_MU_AUTH_SUDO, "true")))
.build();

}

}
14 changes: 14 additions & 0 deletions src/main/java/mu/semte/ch/lib/dto/ChangeSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package mu.semte.ch.lib.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ChangeSet {
private Delta delta;
}
25 changes: 25 additions & 0 deletions src/main/java/mu/semte/ch/lib/dto/DataContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package mu.semte.ch.lib.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import mu.semte.ch.lib.utils.ModelUtils;

@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class DataContainer {
public static String DATA_CONTAINER_PREFIX = "http://redpencil.data.gift/id/dataContainers";

@Builder.Default
private String id = ModelUtils.uuid();
private String graphUri;
private String validationGraphUri;

public String getUri() {
return "%s/%s".formatted(DATA_CONTAINER_PREFIX, id);
}

}
27 changes: 27 additions & 0 deletions src/main/java/mu/semte/ch/lib/dto/Delta.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package mu.semte.ch.lib.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.stream.Collectors;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Delta {
private List<Triple> inserts;
private List<Triple> deletes;

public List<String> getInsertsFor(String predicate, String object) {
return this.inserts
.stream()
.filter(t -> predicate.equals(t.getPredicate().getValue()) && object.equals(t.getObject().getValue()))
.map(t -> t.getSubject().getValue())
.collect(Collectors.toList());
}

}
Loading

0 comments on commit ab40fba

Please sign in to comment.