diff --git a/src/main/java/uk/gov/gchq/palisade/Context.java b/src/main/java/uk/gov/gchq/palisade/Context.java
index 6c17dda4..a06e0ed4 100644
--- a/src/main/java/uk/gov/gchq/palisade/Context.java
+++ b/src/main/java/uk/gov/gchq/palisade/Context.java
@@ -48,39 +48,74 @@ public class Context {
private static final String PURPOSE = "purpose";
private Map contents;
+ /**
+ * Create a new context object with an empty hashMap of attributes
+ */
public Context() {
this(new HashMap<>());
}
+ /**
+ * Create a new context object, passing in a map of attributes
+ *
+ * @param contents a map of attributes, containing a purpose
+ */
@JsonCreator
+ @SuppressWarnings("java:S1699")
public Context(@JsonProperty("contents") final Map contents) {
this.setContents(contents);
}
+ /**
+ * Sets the contents of this Context object
+ *
+ * @param contents a map of contents that will be added to this class
+ * @return the {@link Context} object
+ */
@Generated
public Context contents(final Map contents) {
this.setContents(contents);
return this;
}
-
+ /**
+ * Get the contents map of the {@link Context}
+ *
+ * @return a map of {@link String} and {@link Object}
+ */
@Generated
public Map getContents() {
return contents;
}
+ /**
+ * Set the contents map of the {@link Context}
+ *
+ * @param contents the map to be added to the Context
+ */
@Generated
public void setContents(final Map contents) {
requireNonNull(contents);
this.contents = contents;
}
+ /**
+ * Get a copy of the contents map of the {@link Context}
+ *
+ * @return an unmodifiable map of the contents
+ */
@JsonIgnore
@Generated
public Map getContentsCopy() {
return Collections.unmodifiableMap(contents);
}
+ /**
+ * Adds a purpose, or reason for requesting data to the Context object.
+ *
+ * @param purpose a String containing why the User wants access to the data
+ * @return the Context object with the purpose added to the contents map
+ */
@JsonIgnore
@Generated
public Context purpose(final String purpose) {
@@ -88,6 +123,12 @@ public Context purpose(final String purpose) {
return this;
}
+ /**
+ * Get the purpose from the contents map of the {@link Context}
+ *
+ * @return a string value of the purpose
+ */
+ @SuppressWarnings({"java:S112", "java:S1166"})
@JsonIgnore
public String getPurpose() {
try {
@@ -97,11 +138,24 @@ public String getPurpose() {
}
}
+ /**
+ * Get the purpose by the key value in the map
+ *
+ * @param key the key value associated with the purpose
+ * @return the Object purpose associated with to the String key
+ */
@Generated
public Object get(final String key) {
return contents.get(key);
}
+ /**
+ * Put the provided key and value into the contents map
+ *
+ * @param key the key value
+ * @param value the value object
+ * @return the {@link Context} object
+ */
@Generated
public Context put(final String key, final Object value) {
requireNonNull(key, "The key cannot be null.");
@@ -110,6 +164,13 @@ public Context put(final String key, final Object value) {
return this;
}
+ /**
+ * Put the provided key and value into the contents map if it does not already exist
+ *
+ * @param key the key value
+ * @param value the value object
+ * @return the {@link Context} object
+ */
@Generated
public Context putIfAbsent(final String key, final Object value) {
requireNonNull(key, "The key cannot be null.");
diff --git a/src/main/java/uk/gov/gchq/palisade/Generated.java b/src/main/java/uk/gov/gchq/palisade/Generated.java
index 8827fa73..6fa499f5 100644
--- a/src/main/java/uk/gov/gchq/palisade/Generated.java
+++ b/src/main/java/uk/gov/gchq/palisade/Generated.java
@@ -21,27 +21,27 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/*
+ * Used by JaCoCo and SonarQube, any method annotated with an annotation with
+ * a simple name of "Generated' is ignored from code coverage reports. For best
+ * results, this should be integrated into one's IDE. In IntelliJ, this is done
+ * through: Code ->
+ * Generate ->
+ * [method] ->
+ * ... ->
+ * Prepend "@uk.gov.gchq.palisade.Generated" to the velocity template.
+ *
+ * Alternatively, xml files representing these code generation templates can
+ * be found under ~/.IntelliJIdea${year.version}/config/options:
+ * - equalsHashCodeTemplates.xml
+ * - getterTemplates.xml
+ * - setterTemplates.xml
+ * - toStringTemplates.xml
+ *
+ * It is recommended to include this in all code generation methods used, such
+ * as: equals, hashCode, toString, getters, setters
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Generated {
- /**
- * Used by JaCoCo and SonarQube, any method annotated with an annotation with
- * a simple name of "Generated' is ignored from code coverage reports. For best
- * results, this should be integrated into one's IDE. In IntelliJ, this is done
- * through: Code ->
- * Generate ->
- * [method] ->
- * ... ->
- * Prepend "@uk.gov.gchq.palisade.Generated" to the velocity template.
- *
- * Alternatively, xml files representing these code generation templates can
- * be found under ~/.IntelliJIdea${year.version}/config/options:
- * - equalsHashCodeTemplates.xml
- * - getterTemplates.xml
- * - setterTemplates.xml
- * - toStringTemplates.xml
- *
- * It is recommended to include this in all code generation methods used, such
- * as: equals, hashCode, toString, getters, setters
- */
}
diff --git a/src/main/java/uk/gov/gchq/palisade/RequestId.java b/src/main/java/uk/gov/gchq/palisade/RequestId.java
deleted file mode 100644
index 1ce97974..00000000
--- a/src/main/java/uk/gov/gchq/palisade/RequestId.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade;
-
-
-import java.util.Objects;
-import java.util.StringJoiner;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * This class contains the information that makes a request unique.
- */
-public class RequestId {
-
- private String id;
-
- public RequestId() {
- //no-args constructor needed for serialization only
- }
-
- @Generated
- public RequestId id(final String id) {
- this.setId(id);
- return this;
- }
-
- @Generated
- public String getId() {
- return id;
- }
-
- @Generated
- public void setId(final String id) {
- requireNonNull(id);
- this.id = id;
- }
-
- @Override
- @Generated
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof RequestId)) {
- return false;
- }
- RequestId requestId = (RequestId) o;
- return id.equals(requestId.id);
- }
-
- @Override
- @Generated
- public int hashCode() {
- return Objects.hash(id);
- }
-
- @Override
- @Generated
- public String toString() {
- return new StringJoiner(", ", RequestId.class.getSimpleName() + "[", "]")
- .add("id='" + id + "'")
- .toString();
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/Util.java b/src/main/java/uk/gov/gchq/palisade/Util.java
deleted file mode 100644
index 802d9032..00000000
--- a/src/main/java/uk/gov/gchq/palisade/Util.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import uk.gov.gchq.palisade.rule.Rule;
-import uk.gov.gchq.palisade.rule.Rules;
-
-import java.io.Serializable;
-import java.net.URL;
-import java.security.CodeSource;
-import java.time.Duration;
-import java.util.Objects;
-import java.util.concurrent.Callable;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.stream.Stream;
-
-import static java.util.Objects.isNull;
-import static java.util.Objects.requireNonNull;
-
-/**
- * Common utility methods.
- */
-public final class Util {
- private static final Logger LOGGER = LoggerFactory.getLogger(Util.class);
-
- /**
- * Minimum retry time to wait between attempts.
- */
- public static final Duration MIN_DURATION_PAUSE = Duration.ofSeconds(1);
-
- private Util() {
- }
-
- /**
- * Applies a collection of rules to a record stream.
- *
- * @param records record stream
- * @param user user the records are being processed for
- * @param context the additional context
- * @param rules rules collection
- * @param record type
- * @param recordsProcessed a counter for the number of records being processed
- * @param recordsReturned a counter for the number of records being returned
- * @return filtered stream
- */
- public static Stream applyRulesToStream(final Stream records, final User user, final Context context, final Rules rules, final AtomicLong recordsProcessed, final AtomicLong recordsReturned) {
- Objects.requireNonNull(records);
- if (isNull(rules) || isNull(rules.getRules()) || rules.getRules().isEmpty()) {
- return records;
- }
-
- return records
- .peek(processed -> recordsProcessed.incrementAndGet())
- .map(record -> applyRulesToItem(record, user, context, rules))
- .filter(Objects::nonNull)
- .peek(returned -> recordsReturned.incrementAndGet());
- }
-
- /**
- * Applies a collection of rules to an item (record/resource).
- *
- * @param item resource or record to filter
- * @param user user the record is being processed for
- * @param context the additional context
- * @param rules rules collection
- * @param record type
- * @return item with rules applied
- */
- public static T applyRulesToItem(final T item, final User user, final Context context, final Rules rules) {
- if (isNull(rules) || isNull(rules.getRules()) || rules.getRules().isEmpty()) {
- return item;
- }
- T updateItem = item;
- for (final Rule rule : rules.getRules().values()) {
- updateItem = rule.apply(updateItem, user, context);
- if (null == updateItem) {
- break;
- }
- }
- return updateItem;
- }
-
- /**
- * Create a {@link ThreadFactory} that creates daemon threads that don't prevent JVM exit.
- *
- * @return a daemon thread factory
- */
- public static ThreadFactory createDaemonThreadFactory() {
- //set up a thread to watch this
- final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
- //ensure thread is daemon
- return runnable -> {
- Thread t = defaultFactory.newThread(runnable);
- t.setDaemon(true);
- return t;
- };
- }
-
- /**
- * Carries out the given operation a set number of times in case of failure. The given function will be called and the
- * result returned if successful. If the function throws an exception, then the function is tried again after a pause.
- * If {@code retryCount} attempts fail, then a {@link RuntimeException} is thrown with the most recent cause.
- *
- * @param function the function to run
- * @param retryCount the maximum number of attempts
- * @param pause the pause time between failure
- * @param the return type
- * @return object of type {@code R} from {@code function}
- * @throws IllegalArgumentException if {@code retryCount} less than 1 or {@code pause} is negative or less than the
- * minimum required time
- * @throws RuntimeException if all attempts to execute {@code function} fail
- */
- public static R retryThunker(final Callable function, final int retryCount, final Duration pause) {
- requireNonNull(function, "function");
- requireNonNull(pause, "pause");
- if (retryCount < 1) {
- throw new IllegalArgumentException("retryCount must be >=1");
- }
- if (pause.isNegative()) {
- throw new IllegalArgumentException("pause time cannot be negative");
- }
- if (MIN_DURATION_PAUSE.compareTo(pause) > 0) {
- throw new IllegalArgumentException("pause time must be at least " + MIN_DURATION_PAUSE.toMillis() + " ms");
- }
-
-
- RuntimeException lastCause = null;
- int count = 0;
- long wait = pause.toMillis();
-
- //loop with a count
- while (count < retryCount) {
- try {
- return function.call();
- } catch (RuntimeException r) {
- lastCause = r;
- } catch (Exception e) {
- lastCause = new RuntimeException(e);
- }
-
- //failed so increment count and retry
- count++;
- try {
- if (count < retryCount) {
- Thread.sleep(wait);
- }
- } catch (InterruptedException e) {
- //ignore
- }
- }
-
- //wrap the exception if it is checked
- if (isNull(lastCause)) {
- //shouldn't happen
- throw new RuntimeException("root cause unknown");
- }
- throw lastCause;
- }
-
- /**
- * Captures an exception thrown while running the given function and writes the cause to the log. This is especially
- * useful during connection refused errors as they do not give the host information in their stack trace.
- *
- * @param func the function to protect
- * @param address the address being contacted
- * @param the return type of the function
- * @return dependent on {@code func}
- * @throws Exception any exception thrown by {@code func}
- */
- public static V logConnectionFailed(final Callable func, final URL address) throws Exception {
- try {
- return func.call();
- } catch (Exception e) {
- throw new Exception("Call to " + address.toString() + "failed due to ", e);
- }
- }
-
- /**
- * Debug utility for finding which JAR file (if any) a class was loaded from. This is useful in debugging classpath
- * conflicts.
- *
- * @param clazz the fully qualified class name to search for
- * @return where the class was loaded from, or {@code null}
- */
- public static String locateJarFile(final String clazz) {
- requireNonNull(clazz, "clazz");
- try {
-
- Class c = Class.forName(clazz);
- CodeSource codeSource = c.getProtectionDomain().getCodeSource();
-
- if (codeSource != null) {
- LOGGER.info("{} was loaded from {}", clazz, codeSource.getLocation());
-
- } else {
- LOGGER.info("Can't determine where {} was loaded from", clazz);
- }
- if (codeSource != null) {
- return codeSource.getLocation().toString();
- } else {
- return null;
- }
- } catch (ClassNotFoundException e) {
- LOGGER.error("LocateJarFile threw an exception ", e);
- return e.getMessage();
- }
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/data/serialise/Serialiser.java b/src/main/java/uk/gov/gchq/palisade/data/serialise/Serialiser.java
index f4057fad..bf59ee9f 100644
--- a/src/main/java/uk/gov/gchq/palisade/data/serialise/Serialiser.java
+++ b/src/main/java/uk/gov/gchq/palisade/data/serialise/Serialiser.java
@@ -15,8 +15,6 @@
*/
package uk.gov.gchq.palisade.data.serialise;
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
@@ -57,13 +55,4 @@ public interface Serialiser extends Serializable {
*/
Stream deserialise(final InputStream stream) throws IOException;
- @JsonGetter("class")
- default String getClassName() {
- return getClass().getName();
- }
-
- @JsonSetter("class")
- default void setClassName(final String className) {
- // do nothing.
- }
}
diff --git a/src/main/java/uk/gov/gchq/palisade/exception/Error.java b/src/main/java/uk/gov/gchq/palisade/exception/Error.java
deleted file mode 100644
index f08b3197..00000000
--- a/src/main/java/uk/gov/gchq/palisade/exception/Error.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.exception;
-
-
-import uk.gov.gchq.palisade.Generated;
-import uk.gov.gchq.palisade.util.DebugUtil;
-
-import java.util.Objects;
-import java.util.StringJoiner;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * Simple serialisable POJO for containing details of errors.
- * An {@link uk.gov.gchq.palisade.exception.Error} object is typically
- * created automatically by a Jersey ExceptionMapper and should not be created
- * manually.
- */
-public final class Error {
-
- private int statusCode;
- private Status status;
- private String simpleMessage;
- private String detailMessage;
- private Class extends RuntimeException> exceptionClass;
-
- public Error() {
- }
-
- private Error(final ErrorBuilder builder) {
- this.setStatusCode(builder.statusCode);
- this.setStatus(builder.status);
- this.setSimpleMessage(builder.simpleMessage);
- this.setDetailMessage(builder.detailMessage);
- this.setExceptionClass(builder.exceptionClass);
- }
-
- @Generated
- public int getStatusCode() {
- return statusCode;
- }
-
- @Generated
- public void setStatusCode(final int statusCode) {
- requireNonNull(statusCode);
- this.statusCode = statusCode;
- }
-
- @Generated
- public Status getStatus() {
- return status;
- }
-
- @Generated
- public void setStatus(final Status status) {
- requireNonNull(status);
- this.status = status;
- }
-
- @Generated
- public String getSimpleMessage() {
- return simpleMessage;
- }
-
- @Generated
- public void setSimpleMessage(final String simpleMessage) {
- requireNonNull(simpleMessage);
- this.simpleMessage = simpleMessage;
- }
-
- @Generated
- public String getDetailMessage() {
- return detailMessage;
- }
-
- @Generated
- public void setDetailMessage(final String detailMessage) {
- requireNonNull(detailMessage);
- this.detailMessage = detailMessage;
- }
-
- @Generated
- public Class extends RuntimeException> getExceptionClass() {
- return exceptionClass;
- }
-
- @Generated
- public void setExceptionClass(final Class extends RuntimeException> exceptionClass) {
- requireNonNull(exceptionClass);
- this.exceptionClass = exceptionClass;
- }
-
- @Override
- @Generated
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof Error)) {
- return false;
- }
- Error error = (Error) o;
- return statusCode == error.statusCode &&
- status == error.status &&
- simpleMessage.equals(error.simpleMessage) &&
- detailMessage.equals(error.detailMessage) &&
- exceptionClass.equals(error.exceptionClass);
- }
-
- @Override
- @Generated
- public int hashCode() {
- return Objects.hash(statusCode, status, simpleMessage, detailMessage, exceptionClass);
- }
-
- @Override
- @Generated
- public String toString() {
- return new StringJoiner(", ", Error.class.getSimpleName() + "[", "]")
- .add("statusCode=" + statusCode)
- .add("status=" + status)
- .add("simpleMessage='" + simpleMessage + "'")
- .add("detailMessage='" + detailMessage + "'")
- .add("exceptionClass=" + exceptionClass)
- .toString();
- }
-
-
- public static final class ErrorBuilder {
- private int statusCode;
- private Status status;
- private String simpleMessage;
- private String detailMessage;
- private Class extends RuntimeException> exceptionClass;
-
- public ErrorBuilder() {
- // Empty
- }
-
- public ErrorBuilder statusCode(final int statusCode) {
- this.statusCode = statusCode;
- this.status = Status.fromStatusCode(statusCode);
- return this;
- }
-
- public ErrorBuilder status(final Status status) {
- this.status = status;
- this.statusCode = status.getStatusCode();
- return this;
- }
-
- public ErrorBuilder simpleMessage(final String simpleMessage) {
- this.simpleMessage = simpleMessage;
- return this;
- }
-
- public ErrorBuilder detailMessage(final String detailMessage) {
- this.detailMessage = detailMessage;
- return this;
- }
-
- public ErrorBuilder exceptionClass(final RuntimeException exception) {
- requireNonNull(exception, "exception is required");
- this.exceptionClass = exception.getClass();
- return this;
- }
-
- public ErrorBuilder exceptionClass(final Exception exception) {
- requireNonNull(exception, "exception is required");
- if (exception instanceof RuntimeException) {
- this.exceptionClass = exception.getClass().asSubclass(RuntimeException.class);
- } else {
- this.exceptionClass = PalisadeRuntimeException.class;
- }
- return this;
- }
-
- public ErrorBuilder exceptionClass(final Class extends Exception> exceptionClass) {
- requireNonNull(exceptionClass, "exceptionClass is required");
- if (RuntimeException.class.isAssignableFrom(exceptionClass)) {
- this.exceptionClass = exceptionClass.asSubclass(RuntimeException.class);
- } else {
- this.exceptionClass = PalisadeRuntimeException.class;
- }
- return this;
- }
-
- public Error build() {
- if (DebugUtil.checkDebugMode()) {
- return new Error(this);
- } else {
- return new Error(this.detailMessage(null));
-
- }
- }
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/exception/ErrorFactory.java b/src/main/java/uk/gov/gchq/palisade/exception/ErrorFactory.java
deleted file mode 100644
index 3817b1d6..00000000
--- a/src/main/java/uk/gov/gchq/palisade/exception/ErrorFactory.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.exception;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import uk.gov.gchq.palisade.exception.Error.ErrorBuilder;
-
-import java.util.Arrays;
-import java.util.concurrent.CompletionException;
-import java.util.stream.Collectors;
-
-/**
- * Static utility class to standardise the instantiation of {@link uk.gov.gchq.palisade.exception.Error}
- * objects.
- */
-public final class ErrorFactory {
- private static final Logger LOGGER = LoggerFactory.getLogger(ErrorFactory.class);
-
- /**
- * Empty, private constructor to prevent instantiation.
- */
- private ErrorFactory() {
- // Empty
- }
-
-
-
- /**
- * Create an {@link uk.gov.gchq.palisade.exception.Error} object from a
- * {@link uk.gov.gchq.palisade.exception.PalisadeRuntimeException}.
- *
- * @param gex the exception object
- * @return a newly constructed {@link uk.gov.gchq.palisade.exception.Error}
- */
- public static Error from(final PalisadeRuntimeException gex) {
- LOGGER.error("Error: {}", gex.getMessage(), gex);
- return new ErrorBuilder()
- .status(gex.getStatus())
- .simpleMessage(gex.getMessage())
- .detailMessage(Arrays.asList(gex.getStackTrace()).stream().map(StackTraceElement::toString).collect(Collectors.joining("\n")))
- .exceptionClass(gex)
- .build();
- }
-
-
-
- /**
- * Create an {@link uk.gov.gchq.palisade.exception.Error} object from an
- * {@link Exception}.
- *
- * @param ex the exception object
- * @return a newly constructed {@link uk.gov.gchq.palisade.exception.Error}
- */
- public static Error from(final Exception ex) {
- final Exception unwrappedEx = unwrapCompletionException(ex);
- LOGGER.error("Error: {}", ex.getMessage(), ex);
- return new ErrorBuilder()
- .status(Status.INTERNAL_SERVER_ERROR)
- .simpleMessage(unwrappedEx.getMessage())
- .detailMessage(Arrays.asList(unwrappedEx.getStackTrace()).stream().map(StackTraceElement::toString).collect(Collectors.joining("\n")))
- .exceptionClass(unwrappedEx)
- .build();
- }
-
- private static Exception unwrapCompletionException(final Exception ex) {
- Exception unwrappedEx = ex;
- while (unwrappedEx instanceof CompletionException && unwrappedEx.getCause() instanceof Exception) {
- unwrappedEx = (Exception) ex.getCause();
- }
-
- return unwrappedEx;
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/exception/ForbiddenException.java b/src/main/java/uk/gov/gchq/palisade/exception/ForbiddenException.java
deleted file mode 100644
index 56fbbe03..00000000
--- a/src/main/java/uk/gov/gchq/palisade/exception/ForbiddenException.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.exception;
-
-public class ForbiddenException extends RuntimeException {
- public ForbiddenException() {
- }
-
- public ForbiddenException(final String e) {
- super(e);
- }
-
- public ForbiddenException(final String e, final Throwable t) {
- super(e, t);
- }
-
- public ForbiddenException(final Throwable t) {
- super(t);
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/exception/PalisadeRuntimeException.java b/src/main/java/uk/gov/gchq/palisade/exception/PalisadeRuntimeException.java
deleted file mode 100644
index 22902b26..00000000
--- a/src/main/java/uk/gov/gchq/palisade/exception/PalisadeRuntimeException.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-package uk.gov.gchq.palisade.exception;
-
-import uk.gov.gchq.palisade.Generated;
-
-import java.util.StringJoiner;
-
-import static uk.gov.gchq.palisade.exception.Status.INTERNAL_SERVER_ERROR;
-
-/**
- * Subtype of {@link RuntimeException} with additional constructors to support the inclusion of a HTTP error message
- * along with the other exception details.
- */
-public class PalisadeRuntimeException extends RuntimeException {
-
- private final Status status;
-
- public PalisadeRuntimeException(final String message) {
- this(message, INTERNAL_SERVER_ERROR);
- }
-
- public PalisadeRuntimeException(final Throwable cause) {
- this(cause, INTERNAL_SERVER_ERROR);
- }
-
- public PalisadeRuntimeException(final String message, final Throwable cause) {
- this(message, cause, INTERNAL_SERVER_ERROR);
- }
-
- public PalisadeRuntimeException(final String message, final Status status) {
- super(message);
- this.status = status;
- }
-
- public PalisadeRuntimeException(final Throwable cause, final Status status) {
- super(cause);
- this.status = status;
- }
-
- public PalisadeRuntimeException(final String message, final Throwable cause, final Status status) {
- super(message, cause);
- this.status = status;
- }
-
- @Generated
- public Status getStatus() {
- return status;
- }
-
- @Override
- @Generated
- public String toString() {
- return new StringJoiner(", ", PalisadeRuntimeException.class.getSimpleName() + "[", "]")
- .add("status=" + status)
- .add(super.toString())
- .toString();
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/exception/RequestFailedException.java b/src/main/java/uk/gov/gchq/palisade/exception/RequestFailedException.java
deleted file mode 100644
index 0a804c21..00000000
--- a/src/main/java/uk/gov/gchq/palisade/exception/RequestFailedException.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-package uk.gov.gchq.palisade.exception;
-
-import uk.gov.gchq.palisade.service.request.Request;
-
-/**
- * An abstract exception thrown by Palisade components when unable to satisfy a particular {@link Request}.
- * Exception sub-classes should specify more detailed reasons.
- */
-public abstract class RequestFailedException extends PalisadeRuntimeException {
-
- public RequestFailedException(final String e) {
- super(e);
- }
-
- public RequestFailedException(final Throwable cause) {
- super(cause);
- }
-
- public RequestFailedException(final String e, final Throwable cause) {
- super(e, cause);
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/exception/Status.java b/src/main/java/uk/gov/gchq/palisade/exception/Status.java
deleted file mode 100644
index 7e42da7b..00000000
--- a/src/main/java/uk/gov/gchq/palisade/exception/Status.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-package uk.gov.gchq.palisade.exception;
-
-import uk.gov.gchq.palisade.Generated;
-
-import java.util.Arrays;
-import java.util.StringJoiner;
-
-/**
- * Enumerated types for HTTP status codes, loosely based on the JAX-RS 2.0
- * Status class. Also includes HTTP statuses form the WebDAV HTTP extension.
- */
-public enum Status {
- CONTINUE(100, "Continue"),
- SWITCHING_PROTOCOLS(101, "Switching protocols"),
- PROCESSING(102, "Processing"),
- OK(200, "OK"),
- CREATED(201, "Created"),
- ACCEPTED(202, "Accepted"),
- NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"),
- NO_CONTENT(204, "No Content"),
- RESET_CONTENT(205, "Reset Content"),
- PARTIAL_CONTENT(206, "Partial Content"),
- MULTI_STATUS(207, "Multi Status"),
- ALREADY_REPORTED(208, "Already Reported"),
- IM_USED(226, "IM Used"),
- MULTIPLE_CHOICES(300, "Multiple Choices"),
- MOVED_PERMANENTLY(301, "Moved Permanently"),
- FOUND(302, "Found"),
- SEE_OTHER(303, "See Other"),
- NOT_MODIFIED(304, "Not Modified"),
- USE_PROXY(305, "Use Proxy"),
- SWITCH_PROXY(306, "Switch Proxy"),
- TEMPORARY_REDIRECT(307, "Temporary Redirect"),
- PERMANENT_REDIRECT(308, "Permanent Redirect"),
- BAD_REQUEST(400, "Bad Request"),
- UNAUTHORIZED(401, "Unauthorized"),
- PAYMENT_REQUIRED(402, "Payment Required"),
- FORBIDDEN(403, "Forbidden"),
- NOT_FOUND(404, "Not Found"),
- METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
- NOT_ACCEPTABLE(406, "Not Acceptable"),
- PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"),
- REQUEST_TIMEOUT(408, "Request Timeout"),
- CONFLICT(409, "Conflict"),
- GONE(410, "Gone"),
- LENGTH_REQUIRED(411, "Length Required"),
- PRECONDITION_FAILED(412, "Precondition Failed"),
- REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"),
- REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"),
- UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
- REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested Range Not Satisfiable"),
- EXPECTATION_FAILED(417, "Expectation Failed"),
- IM_A_TEAPOT(418, "I'm A Teapot"),
- MISDIRECTED_REQUEST(421, "Misdirected Request"),
- UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"),
- LOCKED(423, "Locked"),
- FAILED_DEPENDENCY(424, "Failed Dependency"),
- UPGRADE_REQUIRED(426, "Upgrade Required"),
- PRECONDITION_REQUIRED(428, "Precondition Required"),
- TOO_MANY_REQUESTS(429, "Too Many Requests"),
- REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"),
- UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"),
- INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
- NOT_IMPLEMENTED(501, "Not Implemented"),
- BAD_GATEWAY(502, "Bad Gateway"),
- SERVICE_UNAVAILABLE(503, "Service Unavailable"),
- GATEWAY_TIMEOUT(504, "Gateway Timeout"),
- HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version Not Supported");
-
- private final int statusCode;
- private final String reason;
-
- Status(final int statusCode, final String reasonPhrase) {
- this.statusCode = statusCode;
- this.reason = reasonPhrase;
- }
-
- /**
- * Converts a HTTP status code into the matching object.
- *
- * @param statusCode the status code to lookup
- * @return the corresponding status object
- */
- public static Status fromStatusCode(final int statusCode) {
- return Arrays.asList(values())
- .stream()
- .filter(v -> v.getStatusCode() == statusCode)
- .findFirst()
- .orElseThrow(RuntimeException::new);
- }
-
- @Generated
- public int getStatusCode() {
- return statusCode;
- }
-
- @Generated
- public String getReason() {
- return reason;
- }
-
- @Override
- @Generated
- public String toString() {
- return new StringJoiner(", ", Status.class.getSimpleName() + "[", "]")
- .add("statusCode=" + statusCode)
- .add("reason='" + reason + "'")
- .add(super.toString())
- .toString();
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/JSONSerialiser.java b/src/main/java/uk/gov/gchq/palisade/jsonserialisation/JSONSerialiser.java
deleted file mode 100644
index 316fa57d..00000000
--- a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/JSONSerialiser.java
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.jsonserialisation;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonEncoding;
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.core.util.ByteArrayBuilder;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.Module;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectWriter;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.ser.FilterProvider;
-import com.fasterxml.jackson.databind.ser.PropertyFilter;
-import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
-import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
-import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * A {@code JSONSerialiser} provides the ability to serialise and deserialise to/from JSON.
- * The serialisation is set to not include nulls or default values.
- *
- * JSONSerialiser is a singleton. The behaviour of the {@link ObjectMapper}
- * can be configured by extending this class and configuring the ObjectMapper.
- * Child classes must has a default no argument constructor. You will then need
- * to set the palisade.serialiser.json.class property in your StoreProperties or
- * as a System Property. You can also add modules to the ObjectMapper by writing
- * an implementation of {@link JSONSerialiserModules} and registering it using the
- * palisade.serialiser.json.modules property in your StoreProperties or
- * as a System Property.
- *
- *
- * Once the singleton instance has been instantiated it will not be updated,
- * unless update() or update(jsonSerialiserClass, jsonSerialiserModules) is called.
- * An update will be done automatically in the REST API when it is first initialised and
- * also when a Store is initialised.
- *
- */
-public class JSONSerialiser {
- public static final String JSON_SERIALISER_CLASS_KEY = "palisade.serialiser.json.class";
- /**
- * CSV of {@link JSONSerialiserModules} class names. These modules will
- * be added to the {@link ObjectMapper}.
- */
- public static final String JSON_SERIALISER_MODULES = "palisade.serialiser.json.modules";
- public static final String DEFAULT_SERIALISER_CLASS_NAME = JSONSerialiser.class.getName();
-
- public static final String STRICT_JSON = "palisade.serialiser.json.strict";
- public static final boolean STRICT_JSON_DEFAULT = true;
- private static final String STRICT_JSON_DEFAULT_STR = Boolean.toString(STRICT_JSON_DEFAULT);
-
- public static final String FILTER_FIELDS_BY_NAME = "filterFieldsByName";
-
- private static final JsonFactory JSON_FACTORY = new JsonFactory();
- private static final Logger LOGGER = LoggerFactory.getLogger(JSONSerialiser.class);
-
- private static JSONSerialiser instance;
-
- private final ObjectMapper mapper;
-
- /**
- * Constructs a {@code JSONSerialiser} that skips nulls and default values.
- */
- protected JSONSerialiser() {
- this(createDefaultMapper());
- }
-
- /**
- * Constructs a {@code JSONSerialiser} with a custom {@link ObjectMapper}.
- * To create the custom ObjectMapper it is advised that you start with the
- * default mapper provided from JSONSerialiser.createDefaultMapper() then
- * add your custom configuration.
- *
- * @param mapper a custom object mapper
- */
- protected JSONSerialiser(final ObjectMapper mapper) {
- this.mapper = mapper;
- }
-
- /**
- * Child classes of this JSONSerialiser can call this method to register
- * custom modules.
- *
- * @param modules the {@link ObjectMapper} modules to register
- */
- protected void registerModules(final Module... modules) {
- for (final Module module : modules) {
- mapper.registerModule(module);
- }
- }
-
- /**
- * Child classes of this JSONSerialiser can call this method to register
- * custom modules.
- *
- * @param modules the {@link ObjectMapper} modules to register
- */
- protected void registerModules(final Collection modules) {
- modules.forEach(mapper::registerModule);
- }
-
- /**
- * Update the json serialiser with the provided custom properties.
- *
- * @param jsonSerialiserClass the json serialiser class to use (or null to use the default)
- * @param jsonSerialiserModules any extra json serialiser modules required
- * @param strictJson true if strict json conversion should be used
- */
- public static void update(final String jsonSerialiserClass,
- final String jsonSerialiserModules,
- final Boolean strictJson) {
- if (null != jsonSerialiserModules && !jsonSerialiserModules.isEmpty()) {
- final String modulesCsv = deduplicateConcat(
- System.getProperty(JSON_SERIALISER_MODULES),
- jsonSerialiserModules
- );
- System.setProperty(JSON_SERIALISER_MODULES, modulesCsv);
- }
-
- if (null != jsonSerialiserClass) {
- System.setProperty(JSON_SERIALISER_CLASS_KEY, jsonSerialiserClass);
- }
-
- if (null != strictJson) {
- System.setProperty(STRICT_JSON, strictJson.toString());
- }
-
- update();
- }
-
- public static void update() {
- final String jsonSerialiserClass = System.getProperty(JSON_SERIALISER_CLASS_KEY, DEFAULT_SERIALISER_CLASS_NAME);
- final JSONSerialiser newInstance;
- try {
- newInstance = Class.forName(jsonSerialiserClass).asSubclass(JSONSerialiser.class).getDeclaredConstructor().newInstance();
- } catch (final InstantiationException | IllegalAccessException | InvocationTargetException
- | NoSuchMethodException | ClassNotFoundException e) {
- throw new IllegalArgumentException("Property " + JSON_SERIALISER_CLASS_KEY + " must be set to a class that is a sub class of " + JSONSerialiser.class.getName() + ". This class is not valid: " + jsonSerialiserClass, e);
- }
-
- final String moduleFactories = System.getProperty(JSON_SERIALISER_MODULES, "");
- final Set factoryClasses = new HashSet<>(Arrays.asList(moduleFactories.split(",")));
- factoryClasses.remove("");
- for (final String factoryClass : factoryClasses) {
- final JSONSerialiserModules factory;
- try {
- factory = Class.forName(factoryClass).asSubclass(JSONSerialiserModules.class).getDeclaredConstructor().newInstance();
- } catch (final InstantiationException | IllegalAccessException | InvocationTargetException
- | NoSuchMethodException | ClassNotFoundException e) {
- throw new IllegalArgumentException("Property " + JSON_SERIALISER_MODULES + " must be set to a csv of classes that are a sub class of " + JSONSerialiserModules.class.getName() + ". These classes are not valid: " + factoryClass, e);
- }
- final List modules = factory.getModules();
- if (null != modules) {
- newInstance.mapper.registerModules(modules);
- }
- }
-
- newInstance.mapper.configure(
- DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
- Boolean.parseBoolean(System.getProperty(STRICT_JSON, STRICT_JSON_DEFAULT_STR))
- );
-
- instance = newInstance;
- LOGGER.debug("Updated json serialiser to use: {}, and modules: {}", jsonSerialiserClass, moduleFactories);
- }
-
- public static ObjectMapper createDefaultMapper() {
- final ObjectMapper mapper = new ObjectMapper();
- mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
- mapper.configure(SerializationFeature.CLOSE_CLOSEABLE, true);
- mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
-
- // Allow unknown properties. This will help to avoid conflicts between Palisade versions.
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, STRICT_JSON_DEFAULT);
-
- // Add JDK8 module for Optional
- mapper.registerModule(new Jdk8Module());
- // Add JDK8 Time module
- mapper.registerModule(new JavaTimeModule());
-
- mapper.registerModule(ResourceKeySerialiser.getModule());
-
- mapper.registerModule(UserIdKeySerialiser.getModule());
-
- // Use the 'setFilters' method so it is compatible with older versions of jackson
- mapper.setFilterProvider(getFilterProvider());
-
- return mapper;
- }
-
- public static FilterProvider getFilterProvider(final String... fieldsToExclude) {
- if (null == fieldsToExclude || fieldsToExclude.length == 0) {
- // Use the 'serializeAllExcept' method so it is compatible with older versions of jackson
- return new SimpleFilterProvider()
- .addFilter(FILTER_FIELDS_BY_NAME, (PropertyFilter) SimpleBeanPropertyFilter.serializeAllExcept());
- }
-
- return new SimpleFilterProvider()
- .addFilter(FILTER_FIELDS_BY_NAME, (PropertyFilter) SimpleBeanPropertyFilter.serializeAllExcept(fieldsToExclude));
- }
-
- /**
- * @param clazz the clazz of the object to be serialised/deserialised
- * @return true if the clazz can be serialised/deserialised
- */
- public static boolean canHandle(final Class clazz) {
- return getInstance().mapper.canSerialize(clazz);
- }
-
- /**
- * Serialises an object.
- *
- * @param object the object to be serialised
- * @param fieldsToExclude optional property names to exclude from the json
- * @return the provided object serialised into bytes
- * @throws RuntimeException if the object fails to be serialised
- */
- public static byte[] serialise(final Object object, final String... fieldsToExclude) {
- return serialise(object, false, fieldsToExclude);
- }
-
-
- /**
- * Serialises an object.
- *
- * @param object the object to be serialised
- * @param prettyPrint true if the object should be serialised with pretty printing
- * @param fieldsToExclude optional property names to exclude from the json
- * @return the provided object serialised (with pretty printing) into bytes
- * @throws RuntimeException if the object fails to serialise
- */
- public static byte[] serialise(final Object object, final boolean prettyPrint, final String... fieldsToExclude) {
- final ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder();
- try {
- serialise(object, JSON_FACTORY.createGenerator(byteArrayBuilder, JsonEncoding.UTF8), prettyPrint, fieldsToExclude);
- } catch (final IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
-
- return byteArrayBuilder.toByteArray();
- }
-
- /**
- * Serialises an object using the provided json generator.
- *
- * @param object the object to be serialised and written to file
- * @param jsonGenerator the {@link com.fasterxml.jackson.core.JsonGenerator} to use to write the object to
- * @param prettyPrint true if the object should be serialised with pretty printing
- * @param fieldsToExclude optional property names to exclude from the json
- * @throws RuntimeException if the object fails to serialise
- */
- public static void serialise(final Object object, final JsonGenerator jsonGenerator, final boolean prettyPrint, final String... fieldsToExclude) {
- if (prettyPrint) {
- jsonGenerator.useDefaultPrettyPrinter();
- }
-
- final ObjectWriter writer = getInstance().mapper.writer(getFilterProvider(fieldsToExclude));
- try {
- writer.writeValue(jsonGenerator, object);
- } catch (final IOException e) {
- throw new RuntimeException("Failed to serialise object to json: " + e.getMessage(), e);
- }
- }
-
- /**
- * @param json the json of the object to deserialise
- * @param clazz the class of the object to deserialise
- * @param the type of the object
- * @return the deserialised object
- * @throws RuntimeException if the json fails to deserialise
- */
- public static T deserialise(final String json, final Class clazz) {
- try {
- return getInstance().mapper.readValue(json, clazz);
- } catch (final IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- /**
- * @param bytes the bytes of the object to deserialise
- * @param clazz the class of the object to deserialise
- * @param the type of the object
- * @return the deserialised object
- * @throws RuntimeException if the bytes fail to deserialise
- */
- public static T deserialise(final byte[] bytes, final Class clazz) {
- try {
- return getInstance().mapper.readValue(bytes, clazz);
- } catch (final IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- /**
- * @param stream the {@link java.io.InputStream} containing the bytes of the object to deserialise
- * @param clazz the class of the object to deserialise
- * @param the type of the object
- * @return the deserialised object
- * @throws RuntimeException if the bytes fail to deserialise
- */
- public static T deserialise(final InputStream stream, final Class clazz) {
- try (InputStream stream2 = stream) {
- final byte[] bytes = IOUtils.toByteArray(stream2);
- return deserialise(bytes, clazz);
- } catch (final IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- /**
- * @param bytes the bytes of the object to deserialise
- * @param type the type reference of the object to deserialise
- * @param the type of the object
- * @return the deserialised object
- * @throws RuntimeException if the bytes fail to deserialise
- */
- public static T deserialise(final byte[] bytes, final TypeReference type) {
- try {
- return getInstance().mapper.readValue(bytes, type);
- } catch (final IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- /**
- * @param stream the {@link java.io.InputStream} containing the bytes of the object to deserialise
- * @param type the type reference of the object to deserialise
- * @param the type of the object
- * @return the deserialised object
- * @throws RuntimeException if the bytes fail to deserialise
- */
- public static T deserialise(final InputStream stream, final TypeReference type) {
- try (InputStream stream2 = stream) {
- final byte[] bytes = IOUtils.toByteArray(stream2);
- return deserialise(bytes, type);
- } catch (final IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- /**
- * @param content the {@link java.lang.String} containing the bytes of the object to deserialise
- * @return the deserialised object
- * @throws RuntimeException if the bytes fail to deserialise
- */
- public static JsonNode getJsonNodeFromString(final String content) {
- try {
- return getInstance().mapper.readTree(content);
- } catch (final IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- @JsonIgnore
- public static ObjectMapper getMapper() {
- return getInstance().mapper;
- }
-
- @JsonIgnore
- public static JSONSerialiser getInstance() {
- if (null == instance) {
- update();
- }
- return instance;
- }
-
- private static String deduplicateConcat(final String a, final String b) {
- if (null == a) {
- return b;
- }
- if (null == b) {
- return a;
- }
- final LinkedHashSet set = new LinkedHashSet<>();
- Collections.addAll(set, StringUtils.removeStart(a, ",").split(","));
- Collections.addAll(set, StringUtils.removeStart(b, ",").split(","));
- return StringUtils.join(set, ",");
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/JSONSerialiserModules.java b/src/main/java/uk/gov/gchq/palisade/jsonserialisation/JSONSerialiserModules.java
deleted file mode 100644
index edb411e7..00000000
--- a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/JSONSerialiserModules.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.jsonserialisation;
-
-import com.fasterxml.jackson.databind.Module;
-
-import java.util.List;
-
-/**
- * A {@code JSONSerialiserModuleFactory} is a simple factory that returns
- * a list of {@link Module}s to be uses in an {@link com.fasterxml.jackson.databind.ObjectMapper}
- * in {@link uk.gov.gchq.palisade.jsonserialisation.JSONSerialiser}.
- */
-public interface JSONSerialiserModules {
- List getModules();
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/ResourceKeyDeserialiser.java b/src/main/java/uk/gov/gchq/palisade/jsonserialisation/ResourceKeyDeserialiser.java
deleted file mode 100644
index d7eebb03..00000000
--- a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/ResourceKeyDeserialiser.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.jsonserialisation;
-
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.KeyDeserializer;
-
-import uk.gov.gchq.palisade.resource.LeafResource;
-
-import java.io.IOException;
-
-class ResourceKeyDeserialiser extends KeyDeserializer {
- @Override
- public Object deserializeKey(final String key, final DeserializationContext ctxt)
- throws IOException {
- return JSONSerialiser.deserialise(key, LeafResource.class);
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/ResourceKeySerialiser.java b/src/main/java/uk/gov/gchq/palisade/jsonserialisation/ResourceKeySerialiser.java
deleted file mode 100644
index 5cb16f3d..00000000
--- a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/ResourceKeySerialiser.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.jsonserialisation;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import com.fasterxml.jackson.databind.ser.std.StdSerializer;
-
-import uk.gov.gchq.palisade.resource.LeafResource;
-import uk.gov.gchq.palisade.resource.Resource;
-
-import java.io.IOException;
-
-class ResourceKeySerialiser extends StdSerializer {
- private static final long serialVersionUID = 1L;
-
- ResourceKeySerialiser() {
- super(Resource.class);
- }
-
- public static SimpleModule getModule() {
- final SimpleModule module = new SimpleModule();
- module.addKeyDeserializer(LeafResource.class, new ResourceKeyDeserialiser());
- module.addKeySerializer(LeafResource.class, new ResourceKeySerialiser());
- return module;
- }
-
-
- @Override
- public void serialize(final Resource value, final JsonGenerator g, final SerializerProvider provider) throws IOException {
- g.writeFieldName(new String(JSONSerialiser.serialise(value)));
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/UserIdKeyDeserialiser.java b/src/main/java/uk/gov/gchq/palisade/jsonserialisation/UserIdKeyDeserialiser.java
deleted file mode 100644
index 70d39891..00000000
--- a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/UserIdKeyDeserialiser.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.jsonserialisation;
-
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.KeyDeserializer;
-
-import uk.gov.gchq.palisade.UserId;
-
-import java.io.IOException;
-
-class UserIdKeyDeserialiser extends KeyDeserializer {
- @Override
- public Object deserializeKey(final String key, final DeserializationContext ctxt)
- throws IOException {
- return JSONSerialiser.deserialise(key, UserId.class);
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/UserIdKeySerialiser.java b/src/main/java/uk/gov/gchq/palisade/jsonserialisation/UserIdKeySerialiser.java
deleted file mode 100644
index 91a12b59..00000000
--- a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/UserIdKeySerialiser.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.jsonserialisation;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import com.fasterxml.jackson.databind.ser.std.StdSerializer;
-
-import uk.gov.gchq.palisade.UserId;
-
-import java.io.IOException;
-
-public class UserIdKeySerialiser extends StdSerializer {
- private static final long serialVersionUID = 1L;
-
- public UserIdKeySerialiser() {
- super(UserId.class);
- }
-
- public static SimpleModule getModule() {
- final SimpleModule module = new SimpleModule();
- module.addKeyDeserializer(UserId.class, new UserIdKeyDeserialiser());
- module.addKeySerializer(UserId.class, new UserIdKeySerialiser());
- return module;
- }
-
-
- @Override
- public void serialize(final UserId value, final JsonGenerator g, final SerializerProvider provider) throws IOException {
- g.writeFieldName(new String(JSONSerialiser.serialise(value)));
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/package-info.java b/src/main/java/uk/gov/gchq/palisade/jsonserialisation/package-info.java
deleted file mode 100644
index b9465570..00000000
--- a/src/main/java/uk/gov/gchq/palisade/jsonserialisation/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-/**
- * Classes for handling JSON serialisation and deserialisation.
- */
-package uk.gov.gchq.palisade.jsonserialisation;
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/AbstractLeafResource.java b/src/main/java/uk/gov/gchq/palisade/resource/AbstractLeafResource.java
index af4be9b7..fa4df52e 100644
--- a/src/main/java/uk/gov/gchq/palisade/resource/AbstractLeafResource.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/AbstractLeafResource.java
@@ -18,7 +18,6 @@
import uk.gov.gchq.palisade.Generated;
import uk.gov.gchq.palisade.resource.impl.FileResource;
-import uk.gov.gchq.palisade.service.ConnectionDetail;
import java.io.Serializable;
import java.util.HashMap;
@@ -66,8 +65,8 @@ public AbstractLeafResource connectionDetail(final ConnectionDetail connectionDe
/**
* Sets the attributes for the {@link AbstractLeafResource}
*
- * @param attributes a {@link Map} of {@link String} and {@link Serializable}.
- * @return a {@link AbstractLeafResource} object.
+ * @param attributes a {@link Map} of {@link String} and {@link Serializable}.
+ * @return a {@link AbstractLeafResource} object.
*/
@Generated
public AbstractLeafResource attributes(final Map attributes) {
@@ -78,9 +77,9 @@ public AbstractLeafResource attributes(final Map attribute
/**
* Sets the attributes for the {@link AbstractLeafResource}
*
- * @param attributeKey a {@link String} value for the key.
- * @param attributeValue a {@link Serializable} value
- * @return the {@link AbstractLeafResource} object
+ * @param attributeKey a {@link String} value for the key.
+ * @param attributeValue a {@link Serializable} value
+ * @return the {@link AbstractLeafResource} object
*/
@Generated
public AbstractLeafResource attribute(final String attributeKey, final Serializable attributeValue) {
@@ -170,8 +169,8 @@ public Boolean isAttributeSet(final String attributeKey) {
/**
* Sets the key and value of the attributes {@link Map} for the {@link AbstractLeafResource}
*
- * @param attributeKey a {@link String} value for the attribute key.
- * @param attributeValue a {@link Serializable} value for the attribute value.
+ * @param attributeKey a {@link String} value for the attribute key.
+ * @param attributeValue a {@link Serializable} value for the attribute value.
*/
@Generated
public void setAttribute(final String attributeKey, final Serializable attributeValue) {
diff --git a/src/main/java/uk/gov/gchq/palisade/service/ConnectionDetail.java b/src/main/java/uk/gov/gchq/palisade/resource/ConnectionDetail.java
similarity index 93%
rename from src/main/java/uk/gov/gchq/palisade/service/ConnectionDetail.java
rename to src/main/java/uk/gov/gchq/palisade/resource/ConnectionDetail.java
index 147bfac0..744873b9 100644
--- a/src/main/java/uk/gov/gchq/palisade/service/ConnectionDetail.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/ConnectionDetail.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package uk.gov.gchq.palisade.service;
+package uk.gov.gchq.palisade.resource;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -22,6 +22,8 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
+import uk.gov.gchq.palisade.resource.impl.SimpleConnectionDetail;
+
import java.io.Serializable;
/**
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/LeafResource.java b/src/main/java/uk/gov/gchq/palisade/resource/LeafResource.java
index 05eb22ff..267dabca 100644
--- a/src/main/java/uk/gov/gchq/palisade/resource/LeafResource.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/LeafResource.java
@@ -16,8 +16,6 @@
package uk.gov.gchq.palisade.resource;
-import uk.gov.gchq.palisade.service.ConnectionDetail;
-
/**
* A leaf resource is the interface for any resource that can be read for data
* and is not just part of the hierarchical resource structure.
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/impl/DirectoryResource.java b/src/main/java/uk/gov/gchq/palisade/resource/impl/DirectoryResource.java
index 34890bd8..ce55300d 100644
--- a/src/main/java/uk/gov/gchq/palisade/resource/impl/DirectoryResource.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/impl/DirectoryResource.java
@@ -26,6 +26,10 @@
import static java.util.Objects.requireNonNull;
+/**
+ * A DirectoryResource is a Palisade representation of a directory and can have Children and Parent resources
+ * {@code eg. "file:/dev/Palisade/pom.xml" = System "/" -> Directory "/dev/" -> Directory "/dev/Palisade/" -> File "/dev/Palisade/pom.xml" }
+ */
public class DirectoryResource extends AbstractResource implements ChildResource, ParentResource {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/impl/FileResource.java b/src/main/java/uk/gov/gchq/palisade/resource/impl/FileResource.java
index 5c175f37..4ac3cc80 100644
--- a/src/main/java/uk/gov/gchq/palisade/resource/impl/FileResource.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/impl/FileResource.java
@@ -17,12 +17,16 @@
package uk.gov.gchq.palisade.resource.impl;
import uk.gov.gchq.palisade.resource.AbstractLeafResource;
+import uk.gov.gchq.palisade.resource.ConnectionDetail;
import uk.gov.gchq.palisade.resource.ParentResource;
-import uk.gov.gchq.palisade.service.ConnectionDetail;
import java.io.Serializable;
import java.util.Map;
+/**
+ * A FileResource is the Palisade representation of a file, which extends a LeafResource.
+ * {@code eg. "file:/dev/Palisade/pom.xml" = System "/" -> Directory "/dev/" -> Directory "/dev/Palisade/" -> File "/dev/Palisade/pom.xml" }
+ */
public class FileResource extends AbstractLeafResource {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/uk/gov/gchq/palisade/service/SimpleConnectionDetail.java b/src/main/java/uk/gov/gchq/palisade/resource/impl/SimpleConnectionDetail.java
similarity index 94%
rename from src/main/java/uk/gov/gchq/palisade/service/SimpleConnectionDetail.java
rename to src/main/java/uk/gov/gchq/palisade/resource/impl/SimpleConnectionDetail.java
index 60f2dd1c..00d484e5 100644
--- a/src/main/java/uk/gov/gchq/palisade/service/SimpleConnectionDetail.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/impl/SimpleConnectionDetail.java
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-package uk.gov.gchq.palisade.service;
+package uk.gov.gchq.palisade.resource.impl;
import uk.gov.gchq.palisade.Generated;
+import uk.gov.gchq.palisade.resource.ConnectionDetail;
import java.util.Objects;
import java.util.StringJoiner;
@@ -24,7 +25,7 @@
import static java.util.Objects.requireNonNull;
/**
- * A simple implementation of the {@link ConnectionDetail} that holds a reference to the {@link Service}
+ * A simple implementation of the {@link ConnectionDetail} that holds a reference to the Service
*/
public class SimpleConnectionDetail implements ConnectionDetail {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/impl/StreamResource.java b/src/main/java/uk/gov/gchq/palisade/resource/impl/StreamResource.java
deleted file mode 100644
index a1b9d225..00000000
--- a/src/main/java/uk/gov/gchq/palisade/resource/impl/StreamResource.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.resource.impl;
-
-import uk.gov.gchq.palisade.Generated;
-import uk.gov.gchq.palisade.resource.AbstractLeafResource;
-import uk.gov.gchq.palisade.resource.ParentResource;
-import uk.gov.gchq.palisade.service.ConnectionDetail;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Objects;
-import java.util.StringJoiner;
-
-public class StreamResource extends AbstractLeafResource {
- private static final long serialVersionUID = 1L;
-
- protected long start;
- protected long end;
-
- public StreamResource() {
- //no-args constructor needed for serialization only
- }
-
- @Override
- public StreamResource id(final String id) {
- return (StreamResource) super.id(id);
- }
-
- @Override
- public StreamResource type(final String type) {
- return (StreamResource) super.type(type);
- }
-
- @Override
- public StreamResource serialisedFormat(final String serialisedFormat) {
- return (StreamResource) super.serialisedFormat(serialisedFormat);
- }
-
- @Override
- public StreamResource connectionDetail(final ConnectionDetail connectionDetail) {
- return (StreamResource) super.connectionDetail(connectionDetail);
- }
-
- @Override
- public StreamResource attributes(final Map attributes) {
- return (StreamResource) super.attributes(attributes);
- }
-
- @Override
- public StreamResource attribute(final String attributeKey, final Serializable attributeValue) {
- return (StreamResource) super.attribute(attributeKey, attributeValue);
- }
-
- @Override
- public StreamResource parent(final ParentResource parent) {
- return (StreamResource) super.parent(parent);
- }
-
- @Override
- @Generated
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof StreamResource)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- final StreamResource that = (StreamResource) o;
- return start == that.start &&
- end == that.end;
- }
-
- @Override
- @Generated
- public int hashCode() {
- return Objects.hash(super.hashCode(), start, end);
- }
-
- @Override
- @Generated
- public String toString() {
- return new StringJoiner(", ", StreamResource.class.getSimpleName() + "[", "]")
- .add("start=" + start)
- .add("end=" + end)
- .toString();
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/impl/SystemResource.java b/src/main/java/uk/gov/gchq/palisade/resource/impl/SystemResource.java
index 1027c8f1..e0eb87c8 100644
--- a/src/main/java/uk/gov/gchq/palisade/resource/impl/SystemResource.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/impl/SystemResource.java
@@ -19,6 +19,10 @@
import uk.gov.gchq.palisade.resource.AbstractResource;
import uk.gov.gchq.palisade.resource.ParentResource;
+/**
+ * A SystemResource is the Palisade representation of a root directory inside a system
+ * {@code eg. "file:/dev/Palisade/pom.xml" = System "/" -> Directory "/dev/" -> Directory "/dev/Palisade/" -> File "/dev/Palisade/pom.xml" }
+ */
public class SystemResource extends AbstractResource implements ParentResource {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/uk/gov/gchq/palisade/rule/PredicateRule.java b/src/main/java/uk/gov/gchq/palisade/rule/PredicateRule.java
deleted file mode 100644
index ccb8f6cc..00000000
--- a/src/main/java/uk/gov/gchq/palisade/rule/PredicateRule.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.rule;
-
-import uk.gov.gchq.palisade.Context;
-import uk.gov.gchq.palisade.User;
-
-import java.io.Serializable;
-
-/**
- * A {@link PredicateRule} is a simplified implementation of {@link Rule} that simply
- * tests whether a record should be fully redacted or not.
- *
- * @param The type of the record. In normal cases the raw data will be deserialised
- * by the record reader before being passed to the apply(T, User, Context) method.
- */
-public interface PredicateRule extends Rule {
- /**
- * Applies the rule logic to test whether a record should be redacted based on the user and context.
- *
- * @param record the record to be checked.
- * @param user the user
- * @param context the query context
- * @return true if the record should be kept, false if the record should be redacted.
- */
- boolean test(final T record, final User user, final Context context);
-
- @Override
- default T apply(final T obj, final User user, final Context context) {
- if (test(obj, user, context)) {
- return obj;
- } else {
- return null;
-
- }
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/rule/Rule.java b/src/main/java/uk/gov/gchq/palisade/rule/Rule.java
index 6706769d..bae99d9b 100644
--- a/src/main/java/uk/gov/gchq/palisade/rule/Rule.java
+++ b/src/main/java/uk/gov/gchq/palisade/rule/Rule.java
@@ -22,7 +22,7 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import uk.gov.gchq.palisade.Context;
-import uk.gov.gchq.palisade.User;
+import uk.gov.gchq.palisade.user.User;
import java.io.Serializable;
diff --git a/src/main/java/uk/gov/gchq/palisade/rule/Rules.java b/src/main/java/uk/gov/gchq/palisade/rule/Rules.java
index bae1523a..9754bb86 100644
--- a/src/main/java/uk/gov/gchq/palisade/rule/Rules.java
+++ b/src/main/java/uk/gov/gchq/palisade/rule/Rules.java
@@ -17,16 +17,17 @@
package uk.gov.gchq.palisade.rule;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import org.apache.commons.lang3.builder.EqualsBuilder;
import uk.gov.gchq.palisade.Generated;
-import uk.gov.gchq.palisade.jsonserialisation.JSONSerialiser;
import java.io.Serializable;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.StringJoiner;
+import java.util.stream.Collectors;
import static java.util.Objects.requireNonNull;
@@ -101,47 +102,6 @@ public Rules addRule(final String id, final Rule rule) {
return this;
}
- /**
- * Adds a predicate rule.
- *
- * @param id the unique rule id
- * @param rule the predicate rule
- * @return this Rules instance
- */
- @Generated
- public Rules addPredicateRule(final String id, final PredicateRule rule) {
- this.addRule(id, rule);
- return this;
- }
-
- /**
- * Adds a simple predicate rule that just takes the record and returns true or false. Note - using this means your
- * rule will not be given the User or Context.
- *
- * @param id the unique rule id
- * @param rule the simple predicate rule
- * @return this Rules instance
- */
- @Generated
- public Rules addSimplePredicateRule(final String id, final SerializablePredicate rule) {
- this.addRule(id, new WrappedRule<>(rule));
- return this;
- }
-
- /**
- * Adds a simple function rule that just takes the record and returns a modified record or null if the record should
- * be fully redacted. Note - using this means your rule will not be given the User or Context.
- *
- * @param id the unique rule id
- * @param rule the simple function rule
- * @return this Rules instance
- */
- @Generated
- public Rules addSimpleFunctionRule(final String id, final SerializableUnaryOperator rule) {
- this.addRule(id, new WrappedRule<>(rule));
- return this;
- }
-
@Generated
public String getMessage() {
return message;
@@ -175,35 +135,22 @@ public boolean containsRules() {
@Override
public boolean equals(final Object o) {
- boolean rtn = (this == o);
- if (!rtn && (o != null && this.getClass() == o.getClass())) {
-
- final Rules> that = (Rules>) o;
-
- final EqualsBuilder builder = new EqualsBuilder()
- .append(message, that.message)
- .append(this.rulesMap.keySet(), that.getRules().keySet());
-
- if (builder.isEquals()) {
- for (final Map.Entry> entry : this.rulesMap.entrySet()) {
- final String ruleName = entry.getKey();
- final Rule> thisRule = entry.getValue();
- final Rule> thatRule = that.getRules().get(ruleName);
-
- builder.append(thisRule.getClass(), thatRule.getClass());
- if (builder.isEquals()) {
- // This is expensive - but we don't have any other way of doing it
- builder.append(JSONSerialiser.serialise(thisRule), JSONSerialiser.serialise(thatRule));
- }
-
- if (!builder.isEquals()) {
- return false;
- }
- }
- }
- rtn = builder.isEquals();
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Rules)) {
+ return false;
}
- return rtn;
+ Rules> other = (Rules>) o;
+ List>> thisRuleClasses = this.rulesMap.values().stream()
+ .map(Optional::ofNullable)
+ .map(rule -> rule.map(Rule::getClass))
+ .collect(Collectors.toList());
+ List>> otherRuleClasses = other.rulesMap.values().stream()
+ .map(Optional::ofNullable)
+ .map(rule -> rule.map(Rule::getClass))
+ .collect(Collectors.toList());
+ return thisRuleClasses.equals(otherRuleClasses);
}
@Override
@@ -218,7 +165,6 @@ public String toString() {
return new StringJoiner(", ", Rules.class.getSimpleName() + "[", "]")
.add("message='" + message + "'")
.add("rulesHashMap=" + rulesMap)
- .add(super.toString())
.toString();
}
}
diff --git a/src/main/java/uk/gov/gchq/palisade/rule/SerializablePredicate.java b/src/main/java/uk/gov/gchq/palisade/rule/SerializablePredicate.java
deleted file mode 100644
index 16c098b5..00000000
--- a/src/main/java/uk/gov/gchq/palisade/rule/SerializablePredicate.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.rule;
-
-import java.io.Serializable;
-import java.util.function.Predicate;
-
-/**
- * A serializable interface for a {@link Predicate}
- *
- * @param the type of the input to the predicate
- */
-public interface SerializablePredicate extends Predicate, Serializable {
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/rule/SerializableUnaryOperator.java b/src/main/java/uk/gov/gchq/palisade/rule/SerializableUnaryOperator.java
deleted file mode 100644
index aa46f851..00000000
--- a/src/main/java/uk/gov/gchq/palisade/rule/SerializableUnaryOperator.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.rule;
-
-import java.io.Serializable;
-import java.util.function.UnaryOperator;
-
-/**
- * A serializable interface for a {@link UnaryOperator}
- *
- * @param the type of the operand and result of the operator
- */
-public interface SerializableUnaryOperator extends UnaryOperator, Serializable {
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/rule/WrappedRule.java b/src/main/java/uk/gov/gchq/palisade/rule/WrappedRule.java
deleted file mode 100644
index 681db7ef..00000000
--- a/src/main/java/uk/gov/gchq/palisade/rule/WrappedRule.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.rule;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-
-import uk.gov.gchq.palisade.Context;
-import uk.gov.gchq.palisade.Generated;
-import uk.gov.gchq.palisade.User;
-
-import java.io.Serializable;
-import java.util.Objects;
-import java.util.StringJoiner;
-import java.util.function.Predicate;
-import java.util.function.UnaryOperator;
-
-import static java.util.Objects.nonNull;
-import static java.util.Objects.requireNonNull;
-
-/**
- * A {@link WrappedRule} is helper implementation of {@link Rule}. It is useful
- * when you need to set simple rules that don't require the {@link User} or {@link Context}.
- *
- * @param The type of the record. In normal cases the raw data will be deserialised
- * by the record reader before being passed to the {@link Rule#apply(Serializable, User, Context)}.
- */
-@JsonPropertyOrder(value = {"class", "rule", "function", "predicate"}, alphabetic = true)
-public class WrappedRule implements Rule {
-
- public static final String WRAPPED_RULE_WAS_INITIALISED_WITH_NULL = "WrappedRule was initialised with null.";
- public static final String RULE_STRING = "rule";
- public static final String FUNCTION_STRING = "function";
- public static final String PREDICATE_STRING = "predicate";
- private static final long serialVersionUID = 1L;
- private Rule rule;
- private SerializableUnaryOperator function;
- private SerializablePredicate predicate;
-
- /**
- * Constructs a {@link WrappedRule} with a null rule.
- */
- public WrappedRule() {
- }
-
- /**
- * Constructs a {@link WrappedRule} with a given rule to wrap.
- *
- * @param rule the {@link Rule} to wrap.
- */
- public WrappedRule(final Rule rule) {
- requireNonNull(rule, WRAPPED_RULE_WAS_INITIALISED_WITH_NULL + RULE_STRING);
- this.rule = rule;
- }
-
- /**
- * Constructs a {@link WrappedRule} with a given simple function rule to apply.
- * Note - using this means your rule will not be given the User or Context.
- *
- * @param function the simple {@link UnaryOperator} rule to wrap.
- */
- public WrappedRule(final SerializableUnaryOperator function) {
- requireNonNull(function, WRAPPED_RULE_WAS_INITIALISED_WITH_NULL + FUNCTION_STRING);
- this.function = function;
- }
-
- /**
- * Constructs a {@link WrappedRule} with a given simple predicate rule to apply.
- * Note - using this means your rule will not be given the User or Context.
- *
- * @param predicate the simple {@link Predicate} rule to wrap.
- */
- public WrappedRule(final SerializablePredicate predicate) {
- requireNonNull(predicate, WRAPPED_RULE_WAS_INITIALISED_WITH_NULL + PREDICATE_STRING);
- this.predicate = predicate;
- }
-
- @JsonCreator
- public WrappedRule(@JsonProperty("rule") final Rule rule,
- @JsonProperty("function") final SerializableUnaryOperator function,
- @JsonProperty("predicate") final SerializablePredicate predicate) {
- checkNullCount(rule, function, predicate);
- this.rule = rule;
- this.function = function;
- this.predicate = predicate;
- }
-
- private void checkNullCount(final Rule rule, final UnaryOperator function, final Predicate predicate) {
- //needs improving with Jackson
- int nullCount = 0;
- if (rule == null) {
- nullCount++;
- }
- if (function == null) {
- nullCount++;
- }
- if (predicate == null) {
- nullCount++;
- }
- if (nullCount != 2) {
- throw new IllegalArgumentException("Only one constructor parameter can be non-null");
- }
- }
-
- @Override
- public T apply(final T obj, final User user, final Context context) {
- final T rtn;
- if (nonNull(rule)) {
- rtn = rule.apply(obj, user, context);
- } else if (nonNull(function)) {
- rtn = function.apply(obj);
- } else if (nonNull(predicate)) {
- final boolean test = predicate.test(obj);
- if (test) {
- rtn = obj;
- } else {
- rtn = null;
- }
- } else {
- rtn = obj;
- }
- return rtn;
- }
-
-
- @Generated
- public Rule getRule() {
- return rule;
- }
-
- @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "class")
- @Generated
- public UnaryOperator getFunction() {
- return function;
- }
-
- @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "class")
- @Generated
- public Predicate getPredicate() {
- return predicate;
- }
-
- @Override
- @Generated
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof WrappedRule)) {
- return false;
- }
- final WrappedRule> that = (WrappedRule>) o;
- return Objects.equals(rule, that.rule) &&
- Objects.equals(function, that.function) &&
- Objects.equals(predicate, that.predicate);
- }
-
- @Override
- @Generated
- public int hashCode() {
- return Objects.hash(rule, function, predicate);
- }
-
- @Override
- @Generated
- public String toString() {
- return new StringJoiner(", ", WrappedRule.class.getSimpleName() + "[", "]")
- .add("rule=" + rule)
- .add("function=" + function)
- .add("predicate=" + predicate)
- .toString();
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/PolicyConfiguration.java b/src/main/java/uk/gov/gchq/palisade/service/PolicyConfiguration.java
deleted file mode 100644
index 2fdde7b6..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/PolicyConfiguration.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service;
-
-import java.util.List;
-
-public interface PolicyConfiguration {
-
- /**
- * Gets a {@link List} of the {@link PolicyPrepopulationFactory} implemented
- * objects that have been created from a yaml file.
- *
- * @return a {@link List} of the objects that have implemented {@link PolicyPrepopulationFactory}.
- */
- List extends PolicyPrepopulationFactory> getPolicies();
-
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/PolicyPrepopulationFactory.java b/src/main/java/uk/gov/gchq/palisade/service/PolicyPrepopulationFactory.java
deleted file mode 100644
index 647b8d5e..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/PolicyPrepopulationFactory.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service;
-
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonIdentityInfo;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import com.fasterxml.jackson.annotation.JsonSetter;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
-import com.fasterxml.jackson.annotation.ObjectIdGenerators;
-
-import uk.gov.gchq.palisade.resource.LeafResource;
-import uk.gov.gchq.palisade.rule.Rules;
-
-import java.io.Serializable;
-import java.util.Map.Entry;
-
-/**
- * This class defines the top level of the cache prepopulation.
- *
- * The only requirement is that there is a build method, used to create the object
- */
-@JsonPropertyOrder(value = {"class"}, alphabetic = true)
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.CLASS,
- include = As.EXISTING_PROPERTY,
- property = "class"
-)
-@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
-public interface PolicyPrepopulationFactory {
-
- /**
- * Creates a {@link Rules} of type {@link LeafResource} that is associated to a resourceId using the
- * data within an implementation of the {@link PolicyPrepopulationFactory}
- *
- * @return an {@link Entry} value that consists of a resourceId and the created {@link Rules} of type {@link LeafResource}.
- */
- Entry> buildResourceRules();
-
- /**
- * Creates a {@link Rules} of type {@link Serializable} that is associated to a resourceId using the
- * data within an implementation of the {@link PolicyPrepopulationFactory}.
- *
- * @return an {@link Entry} value that consists of a resourceId and the created {@link Rules} of type {@link Serializable}.
- */
- Entry> buildRecordRules();
-
- @JsonGetter("class")
- default String getClassName() {
- return getClass().getName();
- }
-
- @JsonSetter("class")
- default void setClassName(final String className) {
- // do nothing.
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/ResourceConfiguration.java b/src/main/java/uk/gov/gchq/palisade/service/ResourceConfiguration.java
deleted file mode 100644
index c8a43705..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/ResourceConfiguration.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service;
-
-import java.net.URI;
-import java.util.List;
-
-public interface ResourceConfiguration {
-
- /**
- * Gets a {@link List} of the {@link ResourcePrepopulationFactory} implemented
- * objects that have been created from a yaml file, paired with the {@link URI} of the topmost parent
- * that resource should be prepopulated up-to.
- *
- * @return a {@link List} of the objects that have implemented {@link ResourcePrepopulationFactory}.
- */
- List extends ResourcePrepopulationFactory> getResources();
-
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/ResourcePrepopulationFactory.java b/src/main/java/uk/gov/gchq/palisade/service/ResourcePrepopulationFactory.java
deleted file mode 100644
index 2eb3d215..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/ResourcePrepopulationFactory.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service;
-
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonIdentityInfo;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import com.fasterxml.jackson.annotation.JsonSetter;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
-import com.fasterxml.jackson.annotation.ObjectIdGenerators;
-
-import uk.gov.gchq.palisade.resource.LeafResource;
-import uk.gov.gchq.palisade.resource.Resource;
-
-import java.util.Map.Entry;
-import java.util.function.Function;
-
-/**
- * This class defines the top level of persistence prepopulation.
- *
- * The only requirement is that there is a build method to construct a LeafResource
- */
-@JsonPropertyOrder(value = {"class"}, alphabetic = true)
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.CLASS,
- include = As.EXISTING_PROPERTY,
- property = "class"
-)
-@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
-public interface ResourcePrepopulationFactory {
-
- /**
- * Creates a {@link LeafResource} using the data within an implementation of the {@link ResourcePrepopulationFactory}.
- *
- * @param connectionDetailMapper a function mapping the connection detail {@link String}s to proper {@link ConnectionDetail}s
- * @return the {@link LeafResource} that has been created.
- */
- Entry build(Function connectionDetailMapper);
-
- @JsonGetter("class")
- default String getClassName() {
- return getClass().getName();
- }
-
- @JsonSetter("class")
- default void setClassName(final String className) {
- // do nothing.
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/ResourceService.java b/src/main/java/uk/gov/gchq/palisade/service/ResourceService.java
deleted file mode 100644
index 81439947..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/ResourceService.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service;
-
-import uk.gov.gchq.palisade.resource.LeafResource;
-import uk.gov.gchq.palisade.resource.Resource;
-
-import java.util.Iterator;
-
-/**
- * The resource service is the Palisade component that determines what resources are available that meet a specific
- * (type of) request and how they should be accessed. This interface details several methods for obtaining a list of
- * resources, e.g. by type or by data format. The methods of this service all return {@link Iterator}s which link a valid
- * {@link LeafResource} with a {@link ConnectionDetail} object. The ${@link ConnectionDetail} objects contain
- * information on how to set up a connection to retrieve a particular resource. Implementations of this service do not
- * deal with the filtering or application of security policy to the resources. Therefore, a result returned from a
- * method call on this interface doesn't guarantee that the user will be allowed to access it by policy. Other
- * components of the Palisade system will enforce the necessary policy controls to prevent access to resources by users
- * without the necessary access rights.
- * Implementation note: None of the ${@code getResourcesByXXX} methods in this class will return in error if there
- * don't happen to be any resources that do not match a request, instead they will simply return empty ${@link Iterator}
- * instances.
- */
-public interface ResourceService extends Service {
-
- /**
- * Get a list of resources based on a specific resource. This allows for the retrieval of the appropriate {@link
- * ConnectionDetail}s for a given resource. It may also be used to retrieve the details all the resources that are
- * notionally children of another resource. For example, in a standard hierarchical filing system the files in a
- * directory could be considered child resources and calling this method on the directory resource would fetch the
- * details on the contained files.
- *
- * @param resource the resource to request
- * @return an {@link Iterator} of resources, each with an appropriate {@link ConnectionDetail}
- */
- Iterator getResourcesByResource(final Resource resource);
-
- /**
- * Retrieve resource and connection details by resource ID. The request object allows the client to specify the
- * resource ID and obtain the connection details once the returned future has completed.
- *
- * @param resourceId the ID to request
- * @return an {@link Iterator} of resources, each with an appropriate {@link ConnectionDetail}
- */
- Iterator getResourcesById(final String resourceId);
-
- /**
- * Obtain a list of resources that match a specific resource type. This method allows a client to obtain potentially
- * large collections of resources by requesting all the resources of one particular type. For example, a client may
- * request all "employee contact card" records. Please note the warning in the class documentation above, that just
- * because a resource is available does not guarantee that the requesting client has the right to access it.
- *
- * @param type the type of resource to retrieve.
- * @return an {@link Iterator} of resources, each with an appropriate {@link ConnectionDetail}
- */
- Iterator getResourcesByType(final String type);
-
- /**
- * Find all resources that match a particular data format. Resources of a particular data format may not share a
- * type, e.g. not all CSV format records will contain employee contact details. This method allows clients to
- * retrieve all the resources Palisade knows about that conform to one particular format. Note that this method can
- * potentially return large ${@code Map}s with many mappings.
- *
- * @param serialisedFormat the specific format for retrieval
- * @return an {@link Iterator} of resources, each with an appropriate {@link ConnectionDetail}
- */
- Iterator getResourcesBySerialisedFormat(final String serialisedFormat);
-
- /**
- * Informs Palisade about a specific resource that it may return to users. This lets Palisade clients request access
- * to that resource and allows Palisade to provide policy controlled access to it via the other methods in this
- * interface.
- *
- * @param resource the resource that Palisade can manage access to
- * @return whether or not the addResource call completed successfully
- */
- Boolean addResource(final LeafResource resource);
-
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/Service.java b/src/main/java/uk/gov/gchq/palisade/service/Service.java
deleted file mode 100644
index 921398df..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/Service.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service;
-
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonIdentityInfo;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import com.fasterxml.jackson.annotation.JsonSetter;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
-import com.fasterxml.jackson.annotation.ObjectIdGenerators;
-
-/**
- * This class defines the top level services API.
- *
- * The only requirement is that there is a process method, used to process all requests that are passed to a service.
- */
-@JsonPropertyOrder(value = {"class"}, alphabetic = true)
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.CLASS,
- include = As.EXISTING_PROPERTY,
- property = "class"
-)
-@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
-public interface Service {
-
- @JsonGetter("class")
- default String getClassName() {
- return getClass().getName();
- }
-
- @JsonSetter("class")
- default void setClassName(final String className) {
- // do nothing.
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/UserConfiguration.java b/src/main/java/uk/gov/gchq/palisade/service/UserConfiguration.java
deleted file mode 100644
index 5a84ad9b..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/UserConfiguration.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service;
-
-import java.util.List;
-
-public interface UserConfiguration {
-
- /**
- * Gets a {@link List} of the {@link UserPrepopulationFactory} implemented
- * objects that have been created from a yaml file.
- *
- * @return a {@link List} of the objects that have implemented {@link UserPrepopulationFactory}.
- */
- List extends UserPrepopulationFactory> getUsers();
-
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/UserPrepopulationFactory.java b/src/main/java/uk/gov/gchq/palisade/service/UserPrepopulationFactory.java
deleted file mode 100644
index 6d7a9a29..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/UserPrepopulationFactory.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service;
-
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonIdentityInfo;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import com.fasterxml.jackson.annotation.JsonSetter;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
-import com.fasterxml.jackson.annotation.ObjectIdGenerators;
-
-import uk.gov.gchq.palisade.User;
-
-/**
- * This class defines the top level of the cache prepopulation.
- *
- * The only requirement is that there is a warm method, used to create the object
- */
-@JsonPropertyOrder(value = {"class"}, alphabetic = true)
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.CLASS,
- include = As.EXISTING_PROPERTY,
- property = "class"
-)
-@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
-public interface UserPrepopulationFactory {
-
- /**
- * Creates a {@link User} using the data within an implementation of the {@link UserPrepopulationFactory}.
- *
- * @return the {@link User} that has been created.
- */
- User build();
-
- @JsonGetter("class")
- default String getClassName() {
- return getClass().getName();
- }
-
- @JsonSetter("class")
- default void setClassName(final String className) {
- // do nothing.
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/request/DataRequestConfig.java b/src/main/java/uk/gov/gchq/palisade/service/request/DataRequestConfig.java
deleted file mode 100644
index b0d91f4e..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/request/DataRequestConfig.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service.request;
-
-import uk.gov.gchq.palisade.Context;
-import uk.gov.gchq.palisade.Generated;
-import uk.gov.gchq.palisade.User;
-import uk.gov.gchq.palisade.resource.LeafResource;
-import uk.gov.gchq.palisade.rule.Rules;
-
-import java.util.Map;
-import java.util.Objects;
-import java.util.StringJoiner;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * This is the high level API for the object that contains all the information
- * that the data service will require from the palisade, for the data service to
- * respond to requests for access to data.
- */
-public class DataRequestConfig extends Request {
- private User user;
- private Context context;
- private Map rules;
-
- public DataRequestConfig() {
- //no-args constructor needed for serialization only
- }
-
- @Generated
- public DataRequestConfig user(final User user) {
- this.setUser(user);
- return this;
- }
-
- @Generated
- public DataRequestConfig context(final Context context) {
- this.setContext(context);
- return this;
- }
-
- @Generated
- public DataRequestConfig rules(final Map rules) {
- this.setRules(rules);
- return this;
- }
-
-
- @Generated
- public User getUser() {
- return user;
- }
-
- @Generated
- public void setUser(final User user) {
- requireNonNull(user);
- this.user = user;
- }
-
- @Generated
- public Context getContext() {
- return context;
- }
-
- @Generated
- public void setContext(final Context context) {
- requireNonNull(context);
- this.context = context;
- }
-
- @Generated
- public Map getRules() {
- return rules;
- }
-
- @Generated
- public void setRules(final Map rules) {
- requireNonNull(rules);
- this.rules = rules;
- }
-
- @Override
- @Generated
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof DataRequestConfig)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- DataRequestConfig that = (DataRequestConfig) o;
- return user.equals(that.user) &&
- context.equals(that.context) &&
- rules.equals(that.rules);
- }
-
- @Override
- @Generated
- public int hashCode() {
- return Objects.hash(super.hashCode(), user, context, rules);
- }
-
- @Override
- @Generated
- public String toString() {
- return new StringJoiner(", ", DataRequestConfig.class.getSimpleName() + "[", "]")
- .add("user=" + user)
- .add("context=" + context)
- .add("rules=" + rules)
- .add(super.toString())
- .toString();
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/request/DataRequestResponse.java b/src/main/java/uk/gov/gchq/palisade/service/request/DataRequestResponse.java
deleted file mode 100644
index 4600a058..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/request/DataRequestResponse.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service.request;
-
-import uk.gov.gchq.palisade.Generated;
-import uk.gov.gchq.palisade.resource.LeafResource;
-
-import java.util.HashSet;
-import java.util.Objects;
-import java.util.Set;
-import java.util.StringJoiner;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * This is the high level API object that is used to pass back to the client the information it requires to connect to
- * the correct data service implementations and to decide how best to parallelise their job.
- *
- * It is also the object that the client then passes to the data service to access the data. When it is passed to the
- * data service the resources field might have been changed to be a subset of the resources.
- */
-public class DataRequestResponse extends Request {
- private String token;
- private Set resources;
-
- public DataRequestResponse() {
- //no-args constructor needed for serialization only
- }
-
- @Generated
- public DataRequestResponse token(final String token) {
- this.setToken(token);
- return this;
- }
-
- @Generated
- public DataRequestResponse resource(final LeafResource resource) {
- this.addResource(resource);
- return this;
- }
-
- @Generated
- public DataRequestResponse resources(final Set resources) {
- this.setResources(resources);
- return this;
- }
-
-
- public void addResource(final LeafResource resource) {
- requireNonNull(resource);
- if (resources == null) {
- resources = new HashSet<>();
- }
- resources.add(resource);
- }
-
- @Generated
- public String getToken() {
- return token;
- }
-
- @Generated
- public void setToken(final String token) {
- requireNonNull(token);
- this.token = token;
- }
-
- @Generated
- public Set getResources() {
- return resources;
- }
-
- @Generated
- public void setResources(final Set resources) {
- requireNonNull(resources);
- this.resources = resources;
- }
-
- @Override
- @Generated
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof DataRequestResponse)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- DataRequestResponse that = (DataRequestResponse) o;
- return token.equals(that.token) &&
- resources.equals(that.resources);
- }
-
- @Override
- @Generated
- public int hashCode() {
- return Objects.hash(super.hashCode(), token, resources);
- }
-
- @Override
- @Generated
- public String toString() {
- return new StringJoiner(", ", DataRequestResponse.class.getSimpleName() + "[", "]")
- .add("token='" + token + "'")
- .add("resources=" + resources)
- .add(super.toString())
- .toString();
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/service/request/Request.java b/src/main/java/uk/gov/gchq/palisade/service/request/Request.java
deleted file mode 100644
index af3e5176..00000000
--- a/src/main/java/uk/gov/gchq/palisade/service/request/Request.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.service.request;
-
-
-import uk.gov.gchq.palisade.Generated;
-import uk.gov.gchq.palisade.RequestId;
-
-import java.util.Objects;
-import java.util.StringJoiner;
-import java.util.UUID;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * This is the high level API for any request sent to a service.
- * This makes sure each request has a unique identifier.
- */
-public abstract class Request {
- private RequestId id; //this is a unique ID for each individual request made between the micro-services
- private RequestId originalRequestId; //this Id is unique per data access request from a user
-
- public Request() {
- this.id = new RequestId().id(UUID.randomUUID().toString());
- }
-
- @Generated
- public Request originalRequestId(final RequestId originalRequestId) {
- this.setOriginalRequestId(originalRequestId);
- return this;
- }
-
- @Generated
- public RequestId getId() {
- return id;
- }
-
-
- @Generated
- public RequestId getOriginalRequestId() {
- return originalRequestId;
- }
-
- @Generated
- public void setOriginalRequestId(final RequestId originalRequestId) {
- requireNonNull(originalRequestId);
- this.originalRequestId = originalRequestId;
- }
-
- @Override
- @Generated
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof Request)) {
- return false;
- }
- Request request = (Request) o;
- return id.equals(request.id) &&
- originalRequestId.equals(request.originalRequestId);
- }
-
- @Override
- @Generated
- public int hashCode() {
- return Objects.hash(id, originalRequestId);
- }
-
- @Override
- @Generated
- public String toString() {
- return new StringJoiner(", ", Request.class.getSimpleName() + "[", "]")
- .add("id=" + id)
- .add("originalRequestId=" + originalRequestId)
- .toString();
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/User.java b/src/main/java/uk/gov/gchq/palisade/user/User.java
similarity index 98%
rename from src/main/java/uk/gov/gchq/palisade/User.java
rename to src/main/java/uk/gov/gchq/palisade/user/User.java
index 4a96a4f1..bab456d4 100644
--- a/src/main/java/uk/gov/gchq/palisade/User.java
+++ b/src/main/java/uk/gov/gchq/palisade/user/User.java
@@ -14,11 +14,13 @@
* limitations under the License.
*/
-package uk.gov.gchq.palisade;
+package uk.gov.gchq.palisade.user;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import uk.gov.gchq.palisade.Generated;
+
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
diff --git a/src/main/java/uk/gov/gchq/palisade/UserId.java b/src/main/java/uk/gov/gchq/palisade/user/UserId.java
similarity index 96%
rename from src/main/java/uk/gov/gchq/palisade/UserId.java
rename to src/main/java/uk/gov/gchq/palisade/user/UserId.java
index cd7e199c..97bbbd97 100644
--- a/src/main/java/uk/gov/gchq/palisade/UserId.java
+++ b/src/main/java/uk/gov/gchq/palisade/user/UserId.java
@@ -14,7 +14,9 @@
* limitations under the License.
*/
-package uk.gov.gchq.palisade;
+package uk.gov.gchq.palisade.user;
+
+import uk.gov.gchq.palisade.Generated;
import java.io.Serializable;
import java.util.Objects;
diff --git a/src/main/java/uk/gov/gchq/palisade/util/DebugUtil.java b/src/main/java/uk/gov/gchq/palisade/util/DebugUtil.java
deleted file mode 100644
index 9c945db2..00000000
--- a/src/main/java/uk/gov/gchq/palisade/util/DebugUtil.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Util methods for debugging
- */
-public final class DebugUtil {
- public static final String DEBUG = "palisade.error-mode.debug";
- public static final String DEBUG_DEFAULT = String.valueOf(false);
-
- private static Boolean isDebug;
- private static final Logger LOGGER = LoggerFactory.getLogger(DebugUtil.class);
-
- private DebugUtil() {
- // Private constructor to prevent instantiation.
- }
-
- /**
- * Retrieve the value of the debug mode flag.
- *
- * @return the debug mode status, true if enabled, otherwise false
- */
- public static boolean checkDebugMode() {
- if (null == isDebug) {
- updateDebugMode();
- }
- return isDebug;
- }
-
- /**
- * Update the debug mode status by reading the system properties.
- */
- public static void updateDebugMode() {
- try {
- isDebug = Boolean.valueOf(System.getProperty(DEBUG, DEBUG_DEFAULT).trim());
- if (Boolean.TRUE.equals(isDebug)) {
- LOGGER.debug("Debug has been enabled in SystemProperties");
- }
- } catch (final Exception e) {
- LOGGER.error("Defaulting Debug flag. Could not assign from System Properties: {}", e.getMessage());
- isDebug = Boolean.valueOf(DEBUG_DEFAULT);
- }
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java b/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java
index ac8d5012..43ec992b 100644
--- a/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java
+++ b/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java
@@ -19,13 +19,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import uk.gov.gchq.palisade.resource.ConnectionDetail;
import uk.gov.gchq.palisade.resource.LeafResource;
import uk.gov.gchq.palisade.resource.ParentResource;
import uk.gov.gchq.palisade.resource.Resource;
import uk.gov.gchq.palisade.resource.impl.DirectoryResource;
import uk.gov.gchq.palisade.resource.impl.FileResource;
import uk.gov.gchq.palisade.resource.impl.SystemResource;
-import uk.gov.gchq.palisade.service.ConnectionDetail;
import java.io.File;
import java.io.IOException;
@@ -33,6 +33,7 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Collections;
+import java.util.Locale;
import java.util.Map;
import java.util.Objects;
@@ -47,13 +48,17 @@
* - {@link SystemResource}
* Any parents automatically constructed will also be from this collection.
* If another method of creating a resource is required (i.e. directly using strings)
- * there is no guarantee that this can correctly resolve parents. Instead use the
+ * there is no guarantee that this can correctly resolve parents. Instead, use the
* methods provided by the appropriate resource impl.
*/
public class ResourceBuilder {
private static final Logger LOGGER = LoggerFactory.getLogger(ResourceBuilder.class);
private static final URI ROOT;
+ public ResourceBuilder() {
+ // Empty Constructor
+ }
+
static {
File userDir = new File(System.getProperty("user.dir"));
URI root;
@@ -66,27 +71,23 @@ public class ResourceBuilder {
ROOT = root;
}
- private ResourceBuilder() {
- // empty private constructor
- }
-
private enum Scheme {
FILE,
HDFS
}
- public static boolean canCreate(final URI uri) {
- try {
- Scheme.valueOf(uri.getScheme()); // Or throw
- return uri.isAbsolute();
- } catch (IllegalArgumentException ex) {
- return false;
- }
- }
-
- // Create a leafResource from a uri, connectionDetail, type, serialisedFormat and attribute map
- // Throw IllegalArgumentException if unsupported scheme
- // Throw ClassCastException if uri did not point to a leaf resource
+ /**
+ * Create a leafResource from a uri, connectionDetail, type, serialisedFormat and attribute map
+ * Throw IllegalArgumentException if unsupported scheme
+ * Throw ClassCastException if uri did not point to a leaf resource
+ *
+ * @param uri the uri location of the resource
+ * @param connectionDetail the service storing the resource
+ * @param type the type of resource
+ * @param serialisedFormat the format of the resource e.g avro, txt
+ * @param attributes any additional attributes about the resource
+ * @return a new LeafResource populated with these resources
+ */
public static LeafResource create(final URI uri, final ConnectionDetail connectionDetail, final String type, final String serialisedFormat, final Map attributes) {
return ((LeafResource) create(uri, attributes))
.connectionDetail(connectionDetail)
@@ -94,8 +95,14 @@ public static LeafResource create(final URI uri, final ConnectionDetail connecti
.serialisedFormat(serialisedFormat);
}
- // Create a resource from a uri and attribute map
- // Throw IllegalArgumentException if unsupported scheme
+ /**
+ * Create a resource from a uri and attribute map
+ * Throw IllegalArgumentException if unsupported scheme
+ *
+ * @param uri the id of the resource
+ * @param attributes any additional attributes about the resource
+ * @return a new resource created using this uri
+ */
public static Resource create(final URI uri, final Map attributes) {
// If passed relative paths, we can resolve them against the user.dir system property
URI absolute;
@@ -115,7 +122,7 @@ public static Resource create(final URI uri, final Map attribute
// This should be assigning the attributes map to the returned object, once resources support attribute maps
- switch (Scheme.valueOf(normal.getScheme().toUpperCase())) {
+ switch (Scheme.valueOf(normal.getScheme().toUpperCase(Locale.ENGLISH))) {
// Both file:/ and hdfs:/ schema produce filesystem-like structures
case FILE:
case HDFS:
@@ -125,15 +132,41 @@ public static Resource create(final URI uri, final Map attribute
}
}
- // Create a resource from a uri
- // Default to an empty attribute map
- // Throw IllegalArgumentException if unsupported scheme
+ /**
+ * Used to validate URIs and check that they can be created
+ *
+ * @param uri the uri to validate or attach to a resource
+ * @return a boolean true/false if the uri scheme is valid.
+ */
+ public static boolean canCreate(final URI uri) {
+ try {
+ Scheme.valueOf(uri.getScheme()); // Or throw
+ return uri.isAbsolute();
+ } catch (IllegalArgumentException ex) {
+ return false;
+ }
+ }
+
+ /**
+ * Create a resource from a uri
+ * Default to an empty attribute map
+ * Throw IllegalArgumentException if unsupported scheme
+ *
+ * @param uri an id of a resource
+ * @return a newly created resource with an empty map of attributes
+ */
public static Resource create(final URI uri) {
return create(uri, Collections.emptyMap());
}
- // Create a resource from a uri string and attribute map
- // Throw IllegalArgumentException if invalid uri string or unsupported scheme
+ /**
+ * Create a resource from a uri string and attribute map
+ * Throw IllegalArgumentException if invalid uri string or unsupported scheme
+ *
+ * @param uriString a string value of a url used to create a new resource
+ * @param attributes any additional attributes about the resource
+ * @return a newly created resource using these parameters
+ */
public static Resource create(final String uriString, final Map attributes) {
try {
return create(new URI(uriString), attributes);
@@ -142,9 +175,14 @@ public static Resource create(final String uriString, final Map
}
}
- // Create a resource from a uri string
- // Default to an empty attribute map
- // Throw IllegalArgumentException if invalid uri string or unsupported scheme
+ /**
+ * Create a resource from a uri string
+ * Default to an empty attribute map
+ * Throw IllegalArgumentException if invalid uri string or unsupported scheme
+ *
+ * @param uriString a string value of a url used to create a new resource
+ * @return a newly created resource with this url and an empty map of attributes
+ */
public static Resource create(final String uriString) {
return create(uriString, Collections.emptyMap());
}
diff --git a/src/main/java/uk/gov/gchq/palisade/util/RulesUtil.java b/src/main/java/uk/gov/gchq/palisade/util/RulesUtil.java
new file mode 100644
index 00000000..8c1b486b
--- /dev/null
+++ b/src/main/java/uk/gov/gchq/palisade/util/RulesUtil.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2018-2021 Crown Copyright
+ *
+ * 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.
+ */
+
+package uk.gov.gchq.palisade.util;
+
+import uk.gov.gchq.palisade.Context;
+import uk.gov.gchq.palisade.rule.Rule;
+import uk.gov.gchq.palisade.rule.Rules;
+import uk.gov.gchq.palisade.user.User;
+
+import java.io.Serializable;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Stream;
+
+import static java.util.Objects.isNull;
+
+/**
+ * Common utility methods.
+ */
+public final class RulesUtil {
+ private RulesUtil() {
+ }
+
+ /**
+ * Applies a collection of rules to a record stream.
+ *
+ * @param records record stream
+ * @param user user the records are being processed for
+ * @param context the additional context
+ * @param rules rules collection
+ * @param record type
+ * @param recordsProcessed a counter for the number of records being processed
+ * @param recordsReturned a counter for the number of records being returned
+ * @return filtered stream
+ */
+ public static Stream applyRulesToStream(final Stream records, final User user, final Context context, final Rules rules, final AtomicLong recordsProcessed, final AtomicLong recordsReturned) {
+ Objects.requireNonNull(records);
+ if (isNull(rules) || isNull(rules.getRules()) || rules.getRules().isEmpty()) {
+ return records;
+ }
+
+ return records
+ .peek(processed -> recordsProcessed.incrementAndGet())
+ .map(record -> applyRulesToItem(record, user, context, rules))
+ .filter(Objects::nonNull)
+ .peek(returned -> recordsReturned.incrementAndGet());
+ }
+
+ /**
+ * Applies a collection of rules to an item (record/resource).
+ *
+ * @param item resource or record to filter
+ * @param user user the record is being processed for
+ * @param context the additional context
+ * @param rules rules collection
+ * @param record type
+ * @return item with rules applied
+ */
+ public static T applyRulesToItem(final T item, final User user, final Context context, final Rules rules) {
+ if (isNull(rules) || isNull(rules.getRules()) || rules.getRules().isEmpty()) {
+ return item;
+ }
+ T updateItem = item;
+ for (final Rule rule : rules.getRules().values()) {
+ updateItem = rule.apply(updateItem, user, context);
+ if (null == updateItem) {
+ break;
+ }
+ }
+ return updateItem;
+ }
+
+}
diff --git a/src/main/java/uk/gov/gchq/palisade/util/StreamUtil.java b/src/main/java/uk/gov/gchq/palisade/util/StreamUtil.java
deleted file mode 100644
index b54ff84e..00000000
--- a/src/main/java/uk/gov/gchq/palisade/util/StreamUtil.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.Objects;
-
-/**
- * Utility methods for opening {@link InputStream}s.
- */
-public final class StreamUtil {
- private StreamUtil() {
- // Private constructor to prevent instantiation.
- }
-
- /**
- * Open the file found at the the specified path under the location of the given
- * class.
- *
- * @param clazz the class location
- * @param path the path in the class location
- * @return an input stream representating the requested file
- * @throws IllegalArgumentException if there was an error opening the stream
- */
- public static InputStream openStream(final Class clazz, final String path) throws IllegalArgumentException {
- Objects.requireNonNull(path, "Path is required");
- if (new File(path).exists()) {
- try {
- return Files.newInputStream(Paths.get(path));
- } catch (final IOException e) {
- throw new IllegalArgumentException("Unable to load file: " + path, e);
- }
- } else {
- final String checkedPath = formatPathForOpenStream(path);
- final InputStream resourceAsStream = clazz.getResourceAsStream(checkedPath);
- if (null == resourceAsStream) {
- throw new IllegalArgumentException("Unable to load file: " + path);
- }
- return resourceAsStream;
- }
- }
-
- /**
- * Format a path to ensure that it begins with a '/' character.
- *
- * @param path the path to format
- * @return a correctly formatted path string
- */
- public static String formatPathForOpenStream(final String path) {
- if (null == path || path.isEmpty()) {
- throw new IllegalArgumentException("path is required");
- }
- if (path.startsWith("/")) {
- return path;
- } else {
- return "/" + path;
- }
- }
-}
diff --git a/src/main/java/uk/gov/gchq/palisade/util/UriBuilder.java b/src/main/java/uk/gov/gchq/palisade/util/UriBuilder.java
index b00440f0..4de5e3fe 100644
--- a/src/main/java/uk/gov/gchq/palisade/util/UriBuilder.java
+++ b/src/main/java/uk/gov/gchq/palisade/util/UriBuilder.java
@@ -27,17 +27,29 @@
*/
public class UriBuilder {
- private Optional baseUri = Optional.empty();
-
+ /**
+ * The starter method for the Authority Builder class.
+ */
public static class AuthorityBuilder {
private Optional baseUri = Optional.empty();
+ /**
+ * The starter method for the Authority Builder class.
+ *
+ * @param baseUri the uri of the resource to create
+ * @return the composed immutable object
+ */
public static IUserInfo create(final URI baseUri) {
AuthorityBuilder builder = new AuthorityBuilder();
builder.baseUri = Optional.of(baseUri);
return builder.build();
}
+ /**
+ * The starter method for the Builder class without passing in a URI
+ *
+ * @return the composed immutable object
+ */
public static IUserInfo create() {
return new AuthorityBuilder().build();
}
@@ -51,44 +63,104 @@ private IUserInfo build() {
);
}
+ /**
+ * Adds the user info to the URI
+ */
public interface IUserInfo {
+ /**
+ * Adds the user info to the URI
+ *
+ * @param userInfo information about the user that is requesting access to the data. {@code [userinfo@]host[:port]}
+ * @return interface {@link IHost} for the next step in the build.
+ */
IHost withUserInfo(String userInfo);
+ /**
+ * By default, add no user information to the URI
+ *
+ * @return interface {@link IHost} for the next step in the build.
+ */
default IHost withoutUserInfo() {
return withUserInfo(null);
}
}
+ /**
+ * Adds the host to the URI
+ */
public interface IHost {
+ /**
+ * Adds the host to the URI
+ *
+ * @param host the URI host {@code [userinfo@]host[:port]}
+ * @return interface {@link IPort} for the next step in the build.
+ */
IPort withHost(String host);
+ /**
+ * By default, add no host to the URI
+ *
+ * @return interface {@link IPort} for the next step in the build.
+ */
default IPort withoutHost() {
return withHost(null);
}
}
+ /**
+ * Adds the port to the uri
+ */
public interface IPort {
+ /**
+ * Adds the port to the URI
+ *
+ * @param port the URI port {@code [userinfo@]host[:port]}
+ * @return the completed builder and URI object
+ */
String withPort(Integer port);
+ /**
+ * By default, add no port to the URI
+ *
+ * @return the completed builder and URI object.
+ */
default String withoutPort() {
return withPort(null);
}
}
-
}
+ private Optional baseUri = Optional.empty();
+
+ /**
+ * The starter method for the URI Builder class.
+ *
+ * @param baseUri the uri of the resource to create
+ * @return the composed immutable object
+ */
public static IScheme create(final URI baseUri) {
UriBuilder builder = new UriBuilder();
builder.baseUri = Optional.of(baseUri);
return builder.build();
}
+ /**
+ * The starter method for the Builder class.
+ *
+ * @return the composed immutable object
+ */
public static IScheme create() {
return new UriBuilder().build();
}
+ /**
+ * Starter method for the Builder class. This method is called to start the process of creating the
+ * URI class.
+ *
+ * @return interface {@link IScheme} for the next step in the build.
+ */
private IScheme build() {
- return scheme -> authority -> path -> query -> fragment -> {
+ return scheme -> authority -> path -> query -> (String fragment) -> {
String thisScheme = Optional.ofNullable(scheme).or(() -> baseUri.map(URI::getScheme)).orElseThrow();
String thisAuth = Optional.ofNullable(authority).or(() -> baseUri.map(URI::getAuthority)).orElse(null);
String thisPath = Optional.ofNullable(path).or(() -> baseUri.map(URI::getPath)).orElseThrow();
@@ -108,41 +180,111 @@ private IScheme build() {
};
}
+ /**
+ * Adds the scheme to the URI
+ */
public interface IScheme {
+ /**
+ * Adds the {@link URI#getScheme()} to the URI
+ *
+ * @param scheme the string scheme for the uri
+ * @return interface {@link IAuthority} for the next step in the build.
+ */
IAuthority withScheme(String scheme);
+ /**
+ * By default, create the uri without a scheme
+ *
+ * @return interface {@link IAuthority} for the next step in the build.
+ */
default IAuthority withoutScheme() {
return withScheme(null);
}
}
+ /**
+ * Adds the authority to the URI
+ */
public interface IAuthority {
+ /**
+ * Adds the {@link URI#getAuthority()} to the URI
+ *
+ * @param authority the string authority for the uri
+ * @return interface {@link IPath} for the next step in the build.
+ */
IPath withAuthority(String authority);
+ /**
+ * By default, create a uri without the authority
+ *
+ * @return interface {@link IPath} for the next step in the build
+ */
default IPath withoutAuthority() {
return withAuthority(null);
}
}
+ /**
+ * Adds the path to the URI
+ */
public interface IPath {
+ /**
+ * Adds the {@link URI#getPath()} to the URI
+ *
+ * @param path the string path for the uri
+ * @return interface {@link IQuery} for the next step in the build.
+ */
IQuery withPath(String path);
+ /**
+ * By default, create a uri without the path
+ *
+ * @return interface {@link IQuery} for the next step in the build
+ */
default IQuery withoutPath() {
return withPath(null);
}
}
+ /**
+ * Adds the query to the URI
+ */
public interface IQuery {
+ /**
+ * Adds the {@link URI#getQuery()} to the URI
+ *
+ * @param query the string query for the uri
+ * @return interface {@link IFragment} for the next step in the build.
+ */
IFragment withQuery(String query);
+ /**
+ * By default, create a uri without the query
+ *
+ * @return interface {@link IFragment} for the next step in the build
+ */
default IFragment withoutQuery() {
return withQuery(null);
}
}
+ /**
+ * Adds the fragment to the URI
+ */
public interface IFragment {
+ /**
+ * Adds the {@link URI#getFragment()} to the URI
+ *
+ * @param fragment the string fragment for the uri
+ * @return a now completed URI object
+ */
URI withFragment(String fragment);
+ /**
+ * By default, create a uri without a fragment
+ *
+ * @return a now completed URI object
+ */
default URI withoutFragment() {
return withFragment(null);
}
diff --git a/src/test/java/uk/gov/gchq/palisade/ContextTest.java b/src/test/java/uk/gov/gchq/palisade/ContextTest.java
deleted file mode 100644
index c300caa7..00000000
--- a/src/test/java/uk/gov/gchq/palisade/ContextTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-package uk.gov.gchq.palisade;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import uk.gov.gchq.palisade.jsonserialisation.JSONSerialiser;
-
-public class ContextTest {
-
- private Context testObject;
-
- @Before
- public void setUp() {
- testObject = new Context().purpose("purpose1");
- }
-
- @Test
- public void shouldJsonSerialise() {
- //when
- final byte[] serialise = JSONSerialiser.serialise(testObject, true);
- final Context deserialise = JSONSerialiser.deserialise(serialise, Context.class);
- //then
- Assert.assertEquals("testObject deserialised unsuccessfully: ", testObject, deserialise);
- }
-
- @Test
- public void shouldHistoricalJsonSerialise() {
- //when
- final byte[] serialise = JSONSerialiser.serialise(testObject, true);
-
- String serialised = new String(serialise);
- Context deserialise = JSONSerialiser.deserialise(
- "{\n" +
- " \"contents\" : {\n" +
- " \"purpose\" : \"purpose1\"\n" +
- " },\n" +
- " \"class\" : \"uk.gov.gchq.palisade.Context\"\n" +
- "}", Context.class);
-
- //then
- Assert.assertEquals(new String(serialise), testObject, deserialise);
- }
-}
\ No newline at end of file
diff --git a/src/test/java/uk/gov/gchq/palisade/UtilTest.java b/src/test/java/uk/gov/gchq/palisade/UtilTest.java
deleted file mode 100644
index 54e442a4..00000000
--- a/src/test/java/uk/gov/gchq/palisade/UtilTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade;
-
-import org.junit.Test;
-
-import uk.gov.gchq.palisade.rule.Rules;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static uk.gov.gchq.palisade.Util.applyRulesToItem;
-
-public class UtilTest {
-
- @Test
- public void shouldReturnResourceIfNoRules() {
- //when
- final String actual1 = applyRulesToItem("String", null, null, null);
- final String actual2 = applyRulesToItem("String", null, null, new Rules<>());
- //then
- assertEquals("Only 'String' should be returned if there are no rules", "String", actual1);
- assertEquals("Only 'String' should be returned if there are no rules", "String", actual2);
- }
-
- @Test
- public void shouldUpdateRecord() {
- //given
- final Rules rules = new Rules().addRule("r1", (record, user, context) -> "fromRule");
- //when
- final String actual1 = applyRulesToItem("String", null, null, rules);
- assertEquals("'fromRule' should be returned as the record has been updated", "fromRule", actual1);
- }
-
- @Test
- public void shouldUpdateRecordFromAllRules() {
- //given
- final Rules rules = new Rules()
- .addRule("r1", (record, user, context) -> "fromRule")
- .addRule("r2", (record, user, context) -> record.concat("2ndRule"));
- //when
- final String actual1 = applyRulesToItem("String", null, null, rules);
- //then
- assertEquals("'fromRule2ndRule' should be returned as the record has been updated for all rules", "fromRule" + "2ndRule", actual1);
- }
-
- @Test
- public void shouldUpdateStreamOfRecordsFromAllRules() {
- //given
- final AtomicLong recordsProcessed = new AtomicLong(0);
- final AtomicLong recordsReturned = new AtomicLong(0);
- final Stream stream = Arrays.asList("one", "two").stream();
- final Rules rules = new Rules()
- .addRule("r2", (record, user, context) -> record.concat("2ndRule"))
- .addRule("r3", (record, user, context) -> record.concat("3rdRule"));
- //when
- final List result = Util.applyRulesToStream(stream, null, null, rules, recordsProcessed, recordsReturned).collect(Collectors.toList());
- //then
- assertTrue("The stream of records and rules should be updated and show one2ndRule3rdRule", result.stream().anyMatch(s -> s.equals("one" + "2ndRule" + "3rdRule")));
- assertTrue("The stream of records and rules should be updated and show two2ndRule3rdRule", result.stream().anyMatch(s -> s.equals("two" + "2ndRule" + "3rdRule")));
- assertEquals("2 records should be processed", 2, recordsProcessed.get());
- assertEquals("2 records should be returned", 2, recordsReturned.get());
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/data/serialise/AvroSerialiserTest.java b/src/test/java/uk/gov/gchq/palisade/data/serialise/AvroSerialiserTest.java
deleted file mode 100644
index d4933f02..00000000
--- a/src/test/java/uk/gov/gchq/palisade/data/serialise/AvroSerialiserTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-package uk.gov.gchq.palisade.data.serialise;
-
-import org.apache.avro.Schema;
-import org.apache.avro.file.DataFileStream;
-import org.apache.avro.file.DataFileWriter;
-import org.apache.avro.io.DatumReader;
-import org.apache.avro.io.DatumWriter;
-import org.apache.avro.specific.SpecificData;
-import org.apache.avro.specific.SpecificDatumReader;
-import org.apache.avro.specific.SpecificDatumWriter;
-import org.junit.Test;
-
-import uk.gov.gchq.palisade.jsonserialisation.JSONSerialiser;
-import uk.gov.gchq.palisade.util.JsonAssert;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-import java.util.stream.Stream;
-
-import static org.junit.Assert.assertEquals;
-
-public class AvroSerialiserTest {
-
- public static final int INPUT_SIZE = 100;
- public static final Integer[] INPUT = IntStream.range(0, INPUT_SIZE).boxed().toArray((a) -> new Integer[INPUT_SIZE]);
-
- @Test
- public void shouldConsistentlyPass() throws IOException {
- for (int i = 0; i < 10000; i++) {
- testPrimitiveSerialiseAndDeserialise();
- }
- }
-
- @Test
- public void testPrimitiveSerialise() throws IOException {
- // Given
- final AvroSerialiser serialiser = new AvroSerialiser<>(Integer.class);
-
- // When
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- serialiser.serialise(Stream.of(INPUT), outputStream);
-
- // Then
- final DatumReader datumReader = new SpecificDatumReader<>(Integer.class);
- final DataFileStream in = new DataFileStream<>(new ByteArrayInputStream(outputStream.toByteArray()), datumReader);
- final List deserialised = new ArrayList<>();
- in.forEachRemaining(deserialised::add);
- in.close();
- assertEquals(INPUT_SIZE + " records should be serialised", Arrays.asList(INPUT), deserialised);
- }
-
- @Test
- public void testPrimitiveDeserialise() throws IOException {
- // Given
- final AvroSerialiser serialiser = new AvroSerialiser<>(Integer.class);
-
- final Schema schema = SpecificData.get().getSchema(Integer.class);
- final DatumWriter datumWriter = new SpecificDatumWriter<>(schema);
- final DataFileWriter dataFileWriter = new DataFileWriter<>(datumWriter);
-
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- dataFileWriter.create(schema, outputStream);
- Stream.of(INPUT).forEach(item -> {
- try {
- dataFileWriter.append(item);
- } catch (final IOException e) {
- throw new RuntimeException(e);
- }
- });
- dataFileWriter.flush();
- dataFileWriter.close();
- final InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
-
- // When
- final Stream deserialised = serialiser.deserialise(inputStream);
-
- // Then
- assertEquals(INPUT_SIZE + " records should be serialised", Arrays.asList(INPUT), deserialised.collect(Collectors.toList()));
- }
-
- @Test
- public void testPrimitiveSerialiseAndDeserialise() throws IOException {
- // Given
- final AvroSerialiser serialiser = new AvroSerialiser<>(Integer.class);
-
- // When
- Stream stream = Stream.of(INPUT);
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- serialiser.serialise(stream, outputStream);
- final Stream deserialised = serialiser.deserialise(new ByteArrayInputStream(outputStream.toByteArray()));
-
- // Then
- assertEquals(INPUT_SIZE + " records should be serialised and deserialised", Arrays.asList(INPUT), deserialised.collect(Collectors.toList()));
- }
-
- @Test
- public void shouldSerialiseAndDeserialiseWithClass() throws IOException {
- // Given
- final AvroSerialiser serialiser = new AvroSerialiser<>(TestObj.class);
-
- final List input = Arrays.asList(
- new TestObj("str1A", 1, null),
- new TestObj("str1B", 2, "str2B"),
- TestObj.newBuilder()
- .setFieldStr1("str1C")
- .setFieldInt(null)
- .setFieldStr2("str2C")
- .build()
- );
-
- // When
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- serialiser.serialise(input.stream(), outputStream);
- final Stream deserialised = serialiser.deserialise(new ByteArrayInputStream(outputStream.toByteArray()));
-
- // Then
- assertEquals("The serialised and deserialised TestObj list should match the input list", input, deserialised.collect(Collectors.toList()));
- }
-
- @Test
- public void shouldJsonSerialiseAndDeserialise() {
- // Given
- final AvroSerialiser serialiser = new AvroSerialiser<>(Integer.class);
-
- // When
- final byte[] json = JSONSerialiser.serialise(serialiser, true);
- final Serialiser deserialised = JSONSerialiser.deserialise(json, Serialiser.class);
-
- // Then
- JsonAssert.assertEquals(String.format("{%n" +
- " \"domainClass\" : \"java.lang.Integer\",%n" +
- " \"class\" : \"uk.gov.gchq.palisade.data.serialise.AvroSerialiser\"%n" +
- "}").getBytes(), json);
-
- assertEquals("The deserialised class should be AvroSerialiser", AvroSerialiser.class, deserialised.getClass());
- assertEquals("The serialiser domain class should equal the deserialised domain class", serialiser.getDomainClass(), ((AvroSerialiser) deserialised).getDomainClass());
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/data/serialise/SimpleStringSerialiserTest.java b/src/test/java/uk/gov/gchq/palisade/data/serialise/SimpleStringSerialiserTest.java
deleted file mode 100644
index fa92cbe6..00000000
--- a/src/test/java/uk/gov/gchq/palisade/data/serialise/SimpleStringSerialiserTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-package uk.gov.gchq.palisade.data.serialise;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.junit.Assert.assertEquals;
-
-public class SimpleStringSerialiserTest {
- @Test
- public void shouldDeserialise() {
- // Given
- final SimpleStringSerialiser serialiser = new SimpleStringSerialiser();
- final byte[] input = "line1\nline2".getBytes();
-
- // When
- final Stream result = serialiser.deserialise(new ByteArrayInputStream(input));
-
- // Then
- assertEquals("the deserialised list should be the same as the input byte stream", Arrays.asList("line1", "line2"), result.collect(Collectors.toList()));
- }
-
- @Test
- public void shouldSerialise() throws IOException {
- // Given
- final SimpleStringSerialiser serialiser = new SimpleStringSerialiser();
- final Stream input = Stream.of("line1", "line2");
- final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- // When
- serialiser.serialise(input, bos);
- InputStream inputBytes = new ByteArrayInputStream(bos.toByteArray());
-
- // Then
- assertEquals("The serialised list should be the same as the input byte stream", Arrays.asList("line1", "line2"), IOUtils.readLines(inputBytes, StandardCharsets.UTF_8));
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/data/serialise/TestObj.java b/src/test/java/uk/gov/gchq/palisade/data/serialise/TestObj.java
deleted file mode 100644
index e9bf4073..00000000
--- a/src/test/java/uk/gov/gchq/palisade/data/serialise/TestObj.java
+++ /dev/null
@@ -1,431 +0,0 @@
-/**
- * Autogenerated by Avro
- * DO NOT EDIT DIRECTLY
- */
-package uk.gov.gchq.palisade.data.serialise;
-
-import org.apache.avro.message.BinaryMessageDecoder;
-import org.apache.avro.message.BinaryMessageEncoder;
-import org.apache.avro.message.SchemaStore;
-import org.apache.avro.specific.SpecificData;
-
-@SuppressWarnings("all")
-@org.apache.avro.specific.AvroGenerated
-public class TestObj extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
- private static final long serialVersionUID = 7843905661986499514L;
- public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"TestObj\",\"namespace\":\"uk.gov.gchq.palisade.data.service.impl.serialiser\",\"fields\":[{\"name\":\"fieldStr1\",\"type\":\"string\"},{\"name\":\"fieldInt\",\"type\":[\"int\",\"null\"]},{\"name\":\"fieldStr2\",\"type\":[\"string\",\"null\"]}]}");
-
- public static org.apache.avro.Schema getClassSchema() {
- return SCHEMA$;
- }
-
- private static SpecificData MODEL$ = new SpecificData();
-
- private static final BinaryMessageEncoder ENCODER =
- new BinaryMessageEncoder(MODEL$, SCHEMA$);
-
- private static final BinaryMessageDecoder DECODER =
- new BinaryMessageDecoder(MODEL$, SCHEMA$);
-
- /**
- * Return the BinaryMessageDecoder instance used by this class.
- */
- public static BinaryMessageDecoder getDecoder() {
- return DECODER;
- }
-
- /**
- * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}.
- *
- * @param resolver a {@link SchemaStore} used to find schemas by fingerprint
- */
- public static BinaryMessageDecoder createDecoder(SchemaStore resolver) {
- return new BinaryMessageDecoder(MODEL$, SCHEMA$, resolver);
- }
-
- /**
- * Serializes this TestObj to a ByteBuffer.
- */
- public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
- return ENCODER.encode(this);
- }
-
- /**
- * Deserializes a TestObj from a ByteBuffer.
- */
- public static TestObj fromByteBuffer(
- java.nio.ByteBuffer b) throws java.io.IOException {
- return DECODER.decode(b);
- }
-
- @Deprecated
- public java.lang.CharSequence fieldStr1;
- @Deprecated
- public java.lang.Integer fieldInt;
- @Deprecated
- public java.lang.CharSequence fieldStr2;
-
- /**
- * Default constructor. Note that this does not initialize fields
- * to their default values from the schema. If that is desired then
- * one should use newBuilder().
- */
- public TestObj() {
- }
-
- /**
- * All-args constructor.
- *
- * @param fieldStr1 The new value for fieldStr1
- * @param fieldInt The new value for fieldInt
- * @param fieldStr2 The new value for fieldStr2
- */
- public TestObj(java.lang.CharSequence fieldStr1, java.lang.Integer fieldInt, java.lang.CharSequence fieldStr2) {
- this.fieldStr1 = fieldStr1;
- this.fieldInt = fieldInt;
- this.fieldStr2 = fieldStr2;
- }
-
- public org.apache.avro.Schema getSchema() {
- return SCHEMA$;
- }
-
- // Used by DatumWriter. Applications should not call.
- public java.lang.Object get(int field$) {
- switch (field$) {
- case 0:
- return fieldStr1;
- case 1:
- return fieldInt;
- case 2:
- return fieldStr2;
- default:
- throw new org.apache.avro.AvroRuntimeException("Bad index");
- }
- }
-
- // Used by DatumReader. Applications should not call.
- @SuppressWarnings(value = "unchecked")
- public void put(int field$, java.lang.Object value$) {
- switch (field$) {
- case 0:
- fieldStr1 = (java.lang.CharSequence) value$;
- break;
- case 1:
- fieldInt = (java.lang.Integer) value$;
- break;
- case 2:
- fieldStr2 = (java.lang.CharSequence) value$;
- break;
- default:
- throw new org.apache.avro.AvroRuntimeException("Bad index");
- }
- }
-
- /**
- * Gets the value of the 'fieldStr1' field.
- *
- * @return The value of the 'fieldStr1' field.
- */
- public java.lang.CharSequence getFieldStr1() {
- return fieldStr1;
- }
-
- /**
- * Sets the value of the 'fieldStr1' field.
- *
- * @param value the value to set.
- */
- public void setFieldStr1(java.lang.CharSequence value) {
- this.fieldStr1 = value;
- }
-
- /**
- * Gets the value of the 'fieldInt' field.
- *
- * @return The value of the 'fieldInt' field.
- */
- public java.lang.Integer getFieldInt() {
- return fieldInt;
- }
-
- /**
- * Sets the value of the 'fieldInt' field.
- *
- * @param value the value to set.
- */
- public void setFieldInt(java.lang.Integer value) {
- this.fieldInt = value;
- }
-
- /**
- * Gets the value of the 'fieldStr2' field.
- *
- * @return The value of the 'fieldStr2' field.
- */
- public java.lang.CharSequence getFieldStr2() {
- return fieldStr2;
- }
-
- /**
- * Sets the value of the 'fieldStr2' field.
- *
- * @param value the value to set.
- */
- public void setFieldStr2(java.lang.CharSequence value) {
- this.fieldStr2 = value;
- }
-
- /**
- * Creates a new TestObj RecordBuilder.
- *
- * @return A new TestObj RecordBuilder
- */
- public static TestObj.Builder newBuilder() {
- return new TestObj.Builder();
- }
-
- /**
- * Creates a new TestObj RecordBuilder by copying an existing Builder.
- *
- * @param other The existing builder to copy.
- * @return A new TestObj RecordBuilder
- */
- public static TestObj.Builder newBuilder(TestObj.Builder other) {
- return new TestObj.Builder(other);
- }
-
- /**
- * Creates a new TestObj RecordBuilder by copying an existing TestObj instance.
- *
- * @param other The existing instance to copy.
- * @return A new TestObj RecordBuilder
- */
- public static TestObj.Builder newBuilder(TestObj other) {
- return new TestObj.Builder(other);
- }
-
- /**
- * RecordBuilder for TestObj instances.
- */
- public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase
- implements org.apache.avro.data.RecordBuilder {
-
- private java.lang.CharSequence fieldStr1;
- private java.lang.Integer fieldInt;
- private java.lang.CharSequence fieldStr2;
-
- /**
- * Creates a new Builder
- */
- private Builder() {
- super(SCHEMA$);
- }
-
- /**
- * Creates a Builder by copying an existing Builder.
- *
- * @param other The existing Builder to copy.
- */
- private Builder(TestObj.Builder other) {
- super(other);
- if (isValidValue(fields()[0], other.fieldStr1)) {
- this.fieldStr1 = data().deepCopy(fields()[0].schema(), other.fieldStr1);
- fieldSetFlags()[0] = true;
- }
- if (isValidValue(fields()[1], other.fieldInt)) {
- this.fieldInt = data().deepCopy(fields()[1].schema(), other.fieldInt);
- fieldSetFlags()[1] = true;
- }
- if (isValidValue(fields()[2], other.fieldStr2)) {
- this.fieldStr2 = data().deepCopy(fields()[2].schema(), other.fieldStr2);
- fieldSetFlags()[2] = true;
- }
- }
-
- /**
- * Creates a Builder by copying an existing TestObj instance
- *
- * @param other The existing instance to copy.
- */
- private Builder(TestObj other) {
- super(SCHEMA$);
- if (isValidValue(fields()[0], other.fieldStr1)) {
- this.fieldStr1 = data().deepCopy(fields()[0].schema(), other.fieldStr1);
- fieldSetFlags()[0] = true;
- }
- if (isValidValue(fields()[1], other.fieldInt)) {
- this.fieldInt = data().deepCopy(fields()[1].schema(), other.fieldInt);
- fieldSetFlags()[1] = true;
- }
- if (isValidValue(fields()[2], other.fieldStr2)) {
- this.fieldStr2 = data().deepCopy(fields()[2].schema(), other.fieldStr2);
- fieldSetFlags()[2] = true;
- }
- }
-
- /**
- * Gets the value of the 'fieldStr1' field.
- *
- * @return The value.
- */
- public java.lang.CharSequence getFieldStr1() {
- return fieldStr1;
- }
-
- /**
- * Sets the value of the 'fieldStr1' field.
- *
- * @param value The value of 'fieldStr1'.
- * @return This builder.
- */
- public TestObj.Builder setFieldStr1(java.lang.CharSequence value) {
- validate(fields()[0], value);
- this.fieldStr1 = value;
- fieldSetFlags()[0] = true;
- return this;
- }
-
- /**
- * Checks whether the 'fieldStr1' field has been set.
- *
- * @return True if the 'fieldStr1' field has been set, false otherwise.
- */
- public boolean hasFieldStr1() {
- return fieldSetFlags()[0];
- }
-
-
- /**
- * Clears the value of the 'fieldStr1' field.
- *
- * @return This builder.
- */
- public TestObj.Builder clearFieldStr1() {
- fieldStr1 = null;
- fieldSetFlags()[0] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'fieldInt' field.
- *
- * @return The value.
- */
- public java.lang.Integer getFieldInt() {
- return fieldInt;
- }
-
- /**
- * Sets the value of the 'fieldInt' field.
- *
- * @param value The value of 'fieldInt'.
- * @return This builder.
- */
- public TestObj.Builder setFieldInt(java.lang.Integer value) {
- validate(fields()[1], value);
- this.fieldInt = value;
- fieldSetFlags()[1] = true;
- return this;
- }
-
- /**
- * Checks whether the 'fieldInt' field has been set.
- *
- * @return True if the 'fieldInt' field has been set, false otherwise.
- */
- public boolean hasFieldInt() {
- return fieldSetFlags()[1];
- }
-
-
- /**
- * Clears the value of the 'fieldInt' field.
- *
- * @return This builder.
- */
- public TestObj.Builder clearFieldInt() {
- fieldInt = null;
- fieldSetFlags()[1] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'fieldStr2' field.
- *
- * @return The value.
- */
- public java.lang.CharSequence getFieldStr2() {
- return fieldStr2;
- }
-
- /**
- * Sets the value of the 'fieldStr2' field.
- *
- * @param value The value of 'fieldStr2'.
- * @return This builder.
- */
- public TestObj.Builder setFieldStr2(java.lang.CharSequence value) {
- validate(fields()[2], value);
- this.fieldStr2 = value;
- fieldSetFlags()[2] = true;
- return this;
- }
-
- /**
- * Checks whether the 'fieldStr2' field has been set.
- *
- * @return True if the 'fieldStr2' field has been set, false otherwise.
- */
- public boolean hasFieldStr2() {
- return fieldSetFlags()[2];
- }
-
-
- /**
- * Clears the value of the 'fieldStr2' field.
- *
- * @return This builder.
- */
- public TestObj.Builder clearFieldStr2() {
- fieldStr2 = null;
- fieldSetFlags()[2] = false;
- return this;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public TestObj build() {
- try {
- TestObj record = new TestObj();
- record.fieldStr1 = fieldSetFlags()[0] ? this.fieldStr1 : (java.lang.CharSequence) defaultValue(fields()[0]);
- record.fieldInt = fieldSetFlags()[1] ? this.fieldInt : (java.lang.Integer) defaultValue(fields()[1]);
- record.fieldStr2 = fieldSetFlags()[2] ? this.fieldStr2 : (java.lang.CharSequence) defaultValue(fields()[2]);
- return record;
- } catch (java.lang.Exception e) {
- throw new org.apache.avro.AvroRuntimeException(e);
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- private static final org.apache.avro.io.DatumWriter
- WRITER$ = (org.apache.avro.io.DatumWriter) MODEL$.createDatumWriter(SCHEMA$);
-
- @Override
- public void writeExternal(java.io.ObjectOutput out)
- throws java.io.IOException {
- WRITER$.write(this, SpecificData.getEncoder(out));
- }
-
- @SuppressWarnings("unchecked")
- private static final org.apache.avro.io.DatumReader
- READER$ = (org.apache.avro.io.DatumReader) MODEL$.createDatumReader(SCHEMA$);
-
- @Override
- public void readExternal(java.io.ObjectInput in)
- throws java.io.IOException {
- READER$.read(this, SpecificData.getDecoder(in));
- }
-
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/data/service/impl/serialiser/TestObj.java b/src/test/java/uk/gov/gchq/palisade/data/service/impl/serialiser/TestObj.java
deleted file mode 100644
index 8dba4466..00000000
--- a/src/test/java/uk/gov/gchq/palisade/data/service/impl/serialiser/TestObj.java
+++ /dev/null
@@ -1,433 +0,0 @@
-/**
- * Autogenerated by Avro
- *
- * DO NOT EDIT DIRECTLY
- */
-
-package uk.gov.gchq.palisade.data.service.impl.serialiser;
-
-import org.apache.avro.message.BinaryMessageDecoder;
-import org.apache.avro.message.BinaryMessageEncoder;
-import org.apache.avro.message.SchemaStore;
-import org.apache.avro.specific.SpecificData;
-
-@SuppressWarnings("all")
-@org.apache.avro.specific.AvroGenerated
-public class TestObj extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
- private static final long serialVersionUID = 7843905661986499514L;
- public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"TestObj\",\"namespace\":\"uk.gov.gchq.palisade.data.service.impl.serialiser\",\"fields\":[{\"name\":\"fieldStr1\",\"type\":\"string\"},{\"name\":\"fieldInt\",\"type\":[\"int\",\"null\"]},{\"name\":\"fieldStr2\",\"type\":[\"string\",\"null\"]}]}");
-
- public static org.apache.avro.Schema getClassSchema() {
- return SCHEMA$;
- }
-
- private static SpecificData MODEL$ = new SpecificData();
-
- private static final BinaryMessageEncoder ENCODER =
- new BinaryMessageEncoder(MODEL$, SCHEMA$);
-
- private static final BinaryMessageDecoder DECODER =
- new BinaryMessageDecoder(MODEL$, SCHEMA$);
-
- /**
- * Return the BinaryMessageDecoder instance used by this class.
- */
- public static BinaryMessageDecoder getDecoder() {
- return DECODER;
- }
-
- /**
- * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}.
- *
- * @param resolver a {@link SchemaStore} used to find schemas by fingerprint
- */
- public static BinaryMessageDecoder createDecoder(SchemaStore resolver) {
- return new BinaryMessageDecoder(MODEL$, SCHEMA$, resolver);
- }
-
- /**
- * Serializes this TestObj to a ByteBuffer.
- */
- public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
- return ENCODER.encode(this);
- }
-
- /**
- * Deserializes a TestObj from a ByteBuffer.
- */
- public static TestObj fromByteBuffer(
- java.nio.ByteBuffer b) throws java.io.IOException {
- return DECODER.decode(b);
- }
-
- @Deprecated
- public java.lang.CharSequence fieldStr1;
- @Deprecated
- public java.lang.Integer fieldInt;
- @Deprecated
- public java.lang.CharSequence fieldStr2;
-
- /**
- * Default constructor. Note that this does not initialize fields
- * to their default values from the schema. If that is desired then
- * one should use newBuilder().
- */
- public TestObj() {
- }
-
- /**
- * All-args constructor.
- *
- * @param fieldStr1 The new value for fieldStr1
- * @param fieldInt The new value for fieldInt
- * @param fieldStr2 The new value for fieldStr2
- */
- public TestObj(java.lang.CharSequence fieldStr1, java.lang.Integer fieldInt, java.lang.CharSequence fieldStr2) {
- this.fieldStr1 = fieldStr1;
- this.fieldInt = fieldInt;
- this.fieldStr2 = fieldStr2;
- }
-
- public org.apache.avro.Schema getSchema() {
- return SCHEMA$;
- }
-
- // Used by DatumWriter. Applications should not call.
- public java.lang.Object get(int field$) {
- switch (field$) {
- case 0:
- return fieldStr1;
- case 1:
- return fieldInt;
- case 2:
- return fieldStr2;
- default:
- throw new org.apache.avro.AvroRuntimeException("Bad index");
- }
- }
-
- // Used by DatumReader. Applications should not call.
- @SuppressWarnings(value = "unchecked")
- public void put(int field$, java.lang.Object value$) {
- switch (field$) {
- case 0:
- fieldStr1 = (java.lang.CharSequence) value$;
- break;
- case 1:
- fieldInt = (java.lang.Integer) value$;
- break;
- case 2:
- fieldStr2 = (java.lang.CharSequence) value$;
- break;
- default:
- throw new org.apache.avro.AvroRuntimeException("Bad index");
- }
- }
-
- /**
- * Gets the value of the 'fieldStr1' field.
- *
- * @return The value of the 'fieldStr1' field.
- */
- public java.lang.CharSequence getFieldStr1() {
- return fieldStr1;
- }
-
- /**
- * Sets the value of the 'fieldStr1' field.
- *
- * @param value the value to set.
- */
- public void setFieldStr1(java.lang.CharSequence value) {
- this.fieldStr1 = value;
- }
-
- /**
- * Gets the value of the 'fieldInt' field.
- *
- * @return The value of the 'fieldInt' field.
- */
- public java.lang.Integer getFieldInt() {
- return fieldInt;
- }
-
- /**
- * Sets the value of the 'fieldInt' field.
- *
- * @param value the value to set.
- */
- public void setFieldInt(java.lang.Integer value) {
- this.fieldInt = value;
- }
-
- /**
- * Gets the value of the 'fieldStr2' field.
- *
- * @return The value of the 'fieldStr2' field.
- */
- public java.lang.CharSequence getFieldStr2() {
- return fieldStr2;
- }
-
- /**
- * Sets the value of the 'fieldStr2' field.
- *
- * @param value the value to set.
- */
- public void setFieldStr2(java.lang.CharSequence value) {
- this.fieldStr2 = value;
- }
-
- /**
- * Creates a new TestObj RecordBuilder.
- *
- * @return A new TestObj RecordBuilder
- */
- public static uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder newBuilder() {
- return new uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder();
- }
-
- /**
- * Creates a new TestObj RecordBuilder by copying an existing Builder.
- *
- * @param other The existing builder to copy.
- * @return A new TestObj RecordBuilder
- */
- public static uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder newBuilder(uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder other) {
- return new uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder(other);
- }
-
- /**
- * Creates a new TestObj RecordBuilder by copying an existing TestObj instance.
- *
- * @param other The existing instance to copy.
- * @return A new TestObj RecordBuilder
- */
- public static uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder newBuilder(uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj other) {
- return new uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder(other);
- }
-
- /**
- * RecordBuilder for TestObj instances.
- */
- public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase
- implements org.apache.avro.data.RecordBuilder {
-
- private java.lang.CharSequence fieldStr1;
- private java.lang.Integer fieldInt;
- private java.lang.CharSequence fieldStr2;
-
- /**
- * Creates a new Builder
- */
- private Builder() {
- super(SCHEMA$);
- }
-
- /**
- * Creates a Builder by copying an existing Builder.
- *
- * @param other The existing Builder to copy.
- */
- private Builder(uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder other) {
- super(other);
- if (isValidValue(fields()[0], other.fieldStr1)) {
- this.fieldStr1 = data().deepCopy(fields()[0].schema(), other.fieldStr1);
- fieldSetFlags()[0] = true;
- }
- if (isValidValue(fields()[1], other.fieldInt)) {
- this.fieldInt = data().deepCopy(fields()[1].schema(), other.fieldInt);
- fieldSetFlags()[1] = true;
- }
- if (isValidValue(fields()[2], other.fieldStr2)) {
- this.fieldStr2 = data().deepCopy(fields()[2].schema(), other.fieldStr2);
- fieldSetFlags()[2] = true;
- }
- }
-
- /**
- * Creates a Builder by copying an existing TestObj instance
- *
- * @param other The existing instance to copy.
- */
- private Builder(uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj other) {
- super(SCHEMA$);
- if (isValidValue(fields()[0], other.fieldStr1)) {
- this.fieldStr1 = data().deepCopy(fields()[0].schema(), other.fieldStr1);
- fieldSetFlags()[0] = true;
- }
- if (isValidValue(fields()[1], other.fieldInt)) {
- this.fieldInt = data().deepCopy(fields()[1].schema(), other.fieldInt);
- fieldSetFlags()[1] = true;
- }
- if (isValidValue(fields()[2], other.fieldStr2)) {
- this.fieldStr2 = data().deepCopy(fields()[2].schema(), other.fieldStr2);
- fieldSetFlags()[2] = true;
- }
- }
-
- /**
- * Gets the value of the 'fieldStr1' field.
- *
- * @return The value.
- */
- public java.lang.CharSequence getFieldStr1() {
- return fieldStr1;
- }
-
- /**
- * Sets the value of the 'fieldStr1' field.
- *
- * @param value The value of 'fieldStr1'.
- * @return This builder.
- */
- public uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder setFieldStr1(java.lang.CharSequence value) {
- validate(fields()[0], value);
- this.fieldStr1 = value;
- fieldSetFlags()[0] = true;
- return this;
- }
-
- /**
- * Checks whether the 'fieldStr1' field has been set.
- *
- * @return True if the 'fieldStr1' field has been set, false otherwise.
- */
- public boolean hasFieldStr1() {
- return fieldSetFlags()[0];
- }
-
-
- /**
- * Clears the value of the 'fieldStr1' field.
- *
- * @return This builder.
- */
- public uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder clearFieldStr1() {
- fieldStr1 = null;
- fieldSetFlags()[0] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'fieldInt' field.
- *
- * @return The value.
- */
- public java.lang.Integer getFieldInt() {
- return fieldInt;
- }
-
- /**
- * Sets the value of the 'fieldInt' field.
- *
- * @param value The value of 'fieldInt'.
- * @return This builder.
- */
- public uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder setFieldInt(java.lang.Integer value) {
- validate(fields()[1], value);
- this.fieldInt = value;
- fieldSetFlags()[1] = true;
- return this;
- }
-
- /**
- * Checks whether the 'fieldInt' field has been set.
- *
- * @return True if the 'fieldInt' field has been set, false otherwise.
- */
- public boolean hasFieldInt() {
- return fieldSetFlags()[1];
- }
-
-
- /**
- * Clears the value of the 'fieldInt' field.
- *
- * @return This builder.
- */
- public uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder clearFieldInt() {
- fieldInt = null;
- fieldSetFlags()[1] = false;
- return this;
- }
-
- /**
- * Gets the value of the 'fieldStr2' field.
- *
- * @return The value.
- */
- public java.lang.CharSequence getFieldStr2() {
- return fieldStr2;
- }
-
- /**
- * Sets the value of the 'fieldStr2' field.
- *
- * @param value The value of 'fieldStr2'.
- * @return This builder.
- */
- public uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder setFieldStr2(java.lang.CharSequence value) {
- validate(fields()[2], value);
- this.fieldStr2 = value;
- fieldSetFlags()[2] = true;
- return this;
- }
-
- /**
- * Checks whether the 'fieldStr2' field has been set.
- *
- * @return True if the 'fieldStr2' field has been set, false otherwise.
- */
- public boolean hasFieldStr2() {
- return fieldSetFlags()[2];
- }
-
-
- /**
- * Clears the value of the 'fieldStr2' field.
- *
- * @return This builder.
- */
- public uk.gov.gchq.palisade.data.service.impl.serialiser.TestObj.Builder clearFieldStr2() {
- fieldStr2 = null;
- fieldSetFlags()[2] = false;
- return this;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public TestObj build() {
- try {
- TestObj record = new TestObj();
- record.fieldStr1 = fieldSetFlags()[0] ? this.fieldStr1 : (java.lang.CharSequence) defaultValue(fields()[0]);
- record.fieldInt = fieldSetFlags()[1] ? this.fieldInt : (java.lang.Integer) defaultValue(fields()[1]);
- record.fieldStr2 = fieldSetFlags()[2] ? this.fieldStr2 : (java.lang.CharSequence) defaultValue(fields()[2]);
- return record;
- } catch (java.lang.Exception e) {
- throw new org.apache.avro.AvroRuntimeException(e);
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- private static final org.apache.avro.io.DatumWriter
- WRITER$ = (org.apache.avro.io.DatumWriter) MODEL$.createDatumWriter(SCHEMA$);
-
- @Override
- public void writeExternal(java.io.ObjectOutput out)
- throws java.io.IOException {
- WRITER$.write(this, SpecificData.getEncoder(out));
- }
-
- @SuppressWarnings("unchecked")
- private static final org.apache.avro.io.DatumReader
- READER$ = (org.apache.avro.io.DatumReader) MODEL$.createDatumReader(SCHEMA$);
-
- @Override
- public void readExternal(java.io.ObjectInput in)
- throws java.io.IOException {
- READER$.read(this, SpecificData.getDecoder(in));
- }
-
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/policy/HasSensitiveAuthRule.java b/src/test/java/uk/gov/gchq/palisade/policy/HasSensitiveAuthRule.java
deleted file mode 100644
index dad9cae8..00000000
--- a/src/test/java/uk/gov/gchq/palisade/policy/HasSensitiveAuthRule.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.policy;
-
-import uk.gov.gchq.palisade.Context;
-import uk.gov.gchq.palisade.User;
-import uk.gov.gchq.palisade.rule.Rule;
-
-import java.io.Serializable;
-
-public class HasSensitiveAuthRule implements Serializable, Rule {
- @Override
- public T apply(final T record, final User user, final Context context) {
- if (user.getAuths().contains("Sensitive")) {
- return record;
- } else {
- return null;
- }
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/policy/HasTestingPurpose.java b/src/test/java/uk/gov/gchq/palisade/policy/HasTestingPurpose.java
deleted file mode 100644
index 34b2dcef..00000000
--- a/src/test/java/uk/gov/gchq/palisade/policy/HasTestingPurpose.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.policy;
-
-import uk.gov.gchq.palisade.Context;
-import uk.gov.gchq.palisade.User;
-import uk.gov.gchq.palisade.rule.Rule;
-
-import java.io.Serializable;
-
-public class HasTestingPurpose implements Serializable, Rule {
- @Override
- public T apply(final T record, final User user, final Context context) {
- if (context.getPurpose().equalsIgnoreCase("testing")) {
- return record;
- } else {
- return null;
- }
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/policy/IsTextResourceRule.java b/src/test/java/uk/gov/gchq/palisade/policy/IsTextResourceRule.java
deleted file mode 100644
index d2d05eb3..00000000
--- a/src/test/java/uk/gov/gchq/palisade/policy/IsTextResourceRule.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.policy;
-
-import uk.gov.gchq.palisade.Context;
-import uk.gov.gchq.palisade.User;
-import uk.gov.gchq.palisade.resource.LeafResource;
-import uk.gov.gchq.palisade.rule.Rule;
-
-import java.io.Serializable;
-
-public class IsTextResourceRule implements Serializable, Rule {
- @Override
- public LeafResource apply(final LeafResource record, final User user, final Context context) {
- if (record.getSerialisedFormat().equalsIgnoreCase("txt")) {
- return record;
- }
- return null;
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/policy/PassThroughRule.java b/src/test/java/uk/gov/gchq/palisade/policy/PassThroughRule.java
deleted file mode 100644
index 569a6a1b..00000000
--- a/src/test/java/uk/gov/gchq/palisade/policy/PassThroughRule.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.policy;
-
-import uk.gov.gchq.palisade.Context;
-import uk.gov.gchq.palisade.User;
-import uk.gov.gchq.palisade.rule.Rule;
-
-import java.io.Serializable;
-
-public class PassThroughRule implements Serializable, Rule {
- @Override
- public T apply(final T record, final User user, final Context context) {
- return record;
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/policy/RulesTest.java b/src/test/java/uk/gov/gchq/palisade/policy/RulesTest.java
deleted file mode 100644
index 6ca75ea5..00000000
--- a/src/test/java/uk/gov/gchq/palisade/policy/RulesTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-package uk.gov.gchq.palisade.policy;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import uk.gov.gchq.palisade.jsonserialisation.JSONSerialiser;
-import uk.gov.gchq.palisade.rule.Rules;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-public class RulesTest {
-
- private Rules rules;
- private byte[] json;
-
- @Before
- public void setUp() {
- rules = new Rules()
- .message("Age off and visibility filtering")
- .addRule("ageOffRule", new TestRule()
- );
- json = JSONSerialiser.serialise(rules, true);
- }
-
- @Test
- public void shouldNotEquals() {
- //given
- final Rules one = new Rules<>();
- one.addRule("one", new TestRule());
-
- final Rules two = new Rules<>();
- two.addRule("two", new TestRule());
-
- //then
- assertNotEquals("The 2 different rules should not match", one, two);
- }
-
- @Test
- public void shouldEquals() {
- final Rules one1 = new Rules<>();
- one1.addRule("one", new TestRule());
-
- final Rules one2 = new Rules<>();
- one2.addRule("one", new TestRule());
-
- assertEquals("The two rules should match", one1, one2);
- }
-
- @Test
- public void shouldSerialiseToEqualObject() {
- Rules deserialise = JSONSerialiser.deserialise(json, Rules.class);
- final String thisSerialise = new String(JSONSerialiser.serialise(this.rules, true));
- final String thatSerialise = new String(JSONSerialiser.serialise(deserialise, true));
-
- assertEquals("Using the deserliased object in the JSONSerialiser should mean that the two strings are the same", thisSerialise, thatSerialise);
- assertEquals("The rules object that has been serialised and deserialised should match the original object", rules, deserialise);
- }
-
- @Test
- public void shouldSerialiseTo() {
- final String text = String.format("{%n" +
- " \"message\" : \"Age off and visibility filtering\",%n" +
- " \"rules\" : {%n" +
- " \"ageOffRule\" : {%n" +
- " \"class\" : \"uk.gov.gchq.palisade.policy.TestRule\"%n" +
- " }%n" +
- " }%n" +
- "}");
-
- assertEquals("The String json rule object should match the json serialised rule object", text, new String(json));
- }
-
- @Test
- public void shouldDeserialiseText() {
- final String text = String.format("{%n" +
- " \"message\" : \"Age off and visibility filtering\",%n" +
- " \"rules\" : {%n" +
- " \"ageOffRule\" : {%n" +
- " \"class\" : \"uk.gov.gchq.palisade.policy.TestRule\"%n" +
- " }%n" +
- " }%n" +
- "}");
-
- final Rules deserialise = JSONSerialiser.deserialise(text, Rules.class);
- assertEquals("When the String json object has been deserialised it should match the original rule object", rules, deserialise);
-
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/policy/TestRule.java b/src/test/java/uk/gov/gchq/palisade/policy/TestRule.java
deleted file mode 100644
index fbcb757d..00000000
--- a/src/test/java/uk/gov/gchq/palisade/policy/TestRule.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.policy;
-
-import uk.gov.gchq.palisade.Context;
-import uk.gov.gchq.palisade.User;
-import uk.gov.gchq.palisade.rule.Rule;
-
-public class TestRule implements Rule {
- @Override
- public String apply(final String item, final User user, final Context context) {
- return item;
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/policy/WrappedRuleTest.java b/src/test/java/uk/gov/gchq/palisade/policy/WrappedRuleTest.java
deleted file mode 100644
index 15ab3674..00000000
--- a/src/test/java/uk/gov/gchq/palisade/policy/WrappedRuleTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-package uk.gov.gchq.palisade.policy;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import uk.gov.gchq.palisade.rule.SerializableUnaryOperator;
-import uk.gov.gchq.palisade.rule.WrappedRule;
-
-public class WrappedRuleTest {
-
- @Test
- public void shouldConstruct1ArgumentWithNoErrors() {
- // Given
- WrappedRule rule1 = new WrappedRule<>(new TestRule(), null, null);
- WrappedRule rule2 = new WrappedRule<>(null, o -> o, null);
- WrappedRule rule3 = new WrappedRule<>(null, null, o -> true);
-
- // Then
- Assert.assertNotNull("rule1 rule should not be null", rule1.getRule());
- Assert.assertNotNull("rule2 function should not be null", rule2.getFunction());
- Assert.assertNotNull("rule3 predicate should not be null", rule3.getPredicate());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldNotConstruct0Arguments() {
- //When
- new WrappedRule<>(null, null, null);
- //Then it should throw an IllegalArgumentException
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldNotConstructNullPredicate() {
- //When
- new WrappedRule<>(new TestRule(), o -> o, null);
- // Then it should throw an IllegalArgumentException
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldNotConstructNullFunction() {
- //When
- new WrappedRule<>(new TestRule(), null, o -> true);
- //Then it should throw an IllegalArgumentException
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldNotConstructNullRule() {
- //When
- new WrappedRule<>(null, (SerializableUnaryOperator) String::toString, o -> true);
- //Then it should throw an IllegalArgumentException
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldNotConstruct3Arguments() {
- //When
- new WrappedRule<>(new TestRule(), o -> o, o -> true);
- //Then it should throw an IllegalArgumentException
- }
-
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/resource/StubResource.java b/src/test/java/uk/gov/gchq/palisade/resource/StubResource.java
deleted file mode 100644
index c9166bef..00000000
--- a/src/test/java/uk/gov/gchq/palisade/resource/StubResource.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.resource;
-
-import uk.gov.gchq.palisade.resource.impl.SystemResource;
-import uk.gov.gchq.palisade.service.ConnectionDetail;
-
-import java.util.Comparator;
-
-public class StubResource extends AbstractLeafResource {
-
- private static final SystemResource PARENT = new SystemResource().id("file");
-
- public StubResource() {
-
- }
-
- public StubResource(final String type, final String id, final String format, final ConnectionDetail connectionDetail) {
- id(id);
- type(type);
- serialisedFormat(format);
- connectionDetail(connectionDetail);
- parent(PARENT);
- }
-
- private static Comparator comp = Comparator.comparing(StubResource::getSerialisedFormat).thenComparing(StubResource::getType).thenComparing(StubResource::getId);
-
- /**
- * {@inheritDoc}
- * Implemented to allow this class to be used in TreeMaps in tests.
- */
- @Override
- public int compareTo(final Resource o) {
- return comp.compare(this, (StubResource) o);
- }
-}
-
diff --git a/src/test/java/uk/gov/gchq/palisade/util/JsonAssert.java b/src/test/java/uk/gov/gchq/palisade/util/JsonAssert.java
deleted file mode 100644
index c06f8df5..00000000
--- a/src/test/java/uk/gov/gchq/palisade/util/JsonAssert.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.util;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Assert;
-
-import uk.gov.gchq.palisade.jsonserialisation.JSONSerialiser;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertNotEquals;
-
-public class JsonAssert {
- private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
-
- public static void assertEquals(final Object expected, final Object actual) {
- final byte[] expectedJson;
- if (expected instanceof byte[]) {
- expectedJson = (byte[]) expected;
- } else if (expected instanceof String) {
- expectedJson = ((String) expected).getBytes();
- } else {
- expectedJson = JSONSerialiser.serialise(expected);
- }
-
- final byte[] actualJson;
- if (actual instanceof byte[]) {
- actualJson = (byte[]) actual;
- } else if (actual instanceof String) {
- actualJson = ((String) actual).getBytes();
- } else {
- actualJson = JSONSerialiser.serialise(actual);
- }
- assertEquals(expectedJson, actualJson);
- }
-
- public static void assertEquals(final String expectedJson, final String actualJson) {
- try {
- final Map expectedSchemaMap = null != expectedJson ? OBJECT_MAPPER.readValue(expectedJson, Map.class) : Collections.emptyMap();
- final Map actualSchemaMap = null != actualJson ? OBJECT_MAPPER.readValue(actualJson, Map.class) : Collections.emptyMap();
- Assert.assertEquals("The actualSchemaMap should equal the expectedSchemaMap", expectedSchemaMap, actualSchemaMap);
- return;
- } catch (final IOException e) {
- // ignore the error and try using lists instead
- }
-
- try {
- final List expectedSchemaList = null != expectedJson ? OBJECT_MAPPER.readValue(expectedJson, List.class) : Collections.emptyList();
- final List actualSchemaList = null != actualJson ? OBJECT_MAPPER.readValue(actualJson, List.class) : Collections.emptyList();
- Assert.assertEquals("The actualSchemaList should equal the expectedSchemaList", expectedSchemaList, actualSchemaList);
- } catch (final IOException e) {
- throw new AssertionError(expectedJson + " is not equal to " + actualJson, e);
- }
- }
-
- public static void assertEquals(final byte[] expectedJson, final byte[] actualJson) {
- assertEquals(null != expectedJson ? new String(expectedJson) : null, null != actualJson ? new String(actualJson) : null);
- }
-
- public static void assertNotEqual(final String firstJson, final String secondJson) {
- try {
- final Map firstSchemaMap = null != firstJson ? OBJECT_MAPPER.readValue(firstJson, Map.class) : Collections.emptyMap();
- final Map secondSchemaMap = null != secondJson ? OBJECT_MAPPER.readValue(secondJson, Map.class) : Collections.emptyMap();
- assertNotEquals("The firstSchemaMap should not equal the secondSchemaMap", firstSchemaMap, secondSchemaMap);
- } catch (final IOException e) {
- // ignore
- }
- }
-
- public static void assertNotEqual(final byte[] firstJson, final byte[] secondJson) {
- assertNotEqual(null != firstJson ? new String(firstJson) : null, null != secondJson ? new String(secondJson) : null);
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/util/ResourceBuilderTest.java b/src/test/java/uk/gov/gchq/palisade/util/ResourceBuilderTest.java
deleted file mode 100644
index 367e69ea..00000000
--- a/src/test/java/uk/gov/gchq/palisade/util/ResourceBuilderTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-package uk.gov.gchq.palisade.util;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import uk.gov.gchq.palisade.resource.ChildResource;
-import uk.gov.gchq.palisade.resource.Resource;
-import uk.gov.gchq.palisade.resource.impl.DirectoryResource;
-import uk.gov.gchq.palisade.resource.impl.FileResource;
-import uk.gov.gchq.palisade.resource.impl.SystemResource;
-
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collections;
-import java.util.LinkedList;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
-@RunWith(JUnit4.class)
-public class ResourceBuilderTest {
-
- @Test(expected = IllegalArgumentException.class)
- public void invalidSchemaThrowsException() throws URISyntaxException {
- // Given
- final URI invalidSchema = new URI("badschema:/path/to/resource");
-
- // Then
- assertFalse("The ResourceBuilder shouldn't be able to create a URI with a bad schema", ResourceBuilder.canCreate(invalidSchema));
-
- // When
- ResourceBuilder.create(invalidSchema);
- // Then throw exception
- }
-
- @Test
- public void shouldCreateSystemResource() {
- // A file schema uri for a system root should return a SystemResource
- // eg. "file:/" = System "/"
-
- // Given
- final File root = new File("/");
-
- // When
- SystemResource systemResource = (SystemResource) ResourceBuilder.create(root.toURI());
-
- // Then
- LinkedList parents = getAllParents(systemResource);
- // System at the 'top'
- assertThat(parents.getFirst(), instanceOf(SystemResource.class));
- parents.removeFirst();
- // Nothing else
- parents.forEach(resource -> fail("parents should be empty so cannot create a system resource"));
- }
-
- @Test
- public void shouldCreateDirectoryResource() {
- // A file schema uri for a directory should return a DirectoryResource
- // The parents of this DirectoryResource should be zero or more DirectoryResources up-to a root SystemResource
- // eg. "file:/dev/Palisade-common/" = System "/" -> Directory "/dev/" -> Directory "/dev/Palisade-common/"
-
- // Given
- final File userDir = new File(System.getProperty("user.dir"));
-
- // When
- DirectoryResource directoryResource = (DirectoryResource) ResourceBuilder.create(userDir.toURI());
-
- // Then
- LinkedList parents = getAllParents(directoryResource);
- // System at the 'top'
- assertThat(parents.getFirst(), instanceOf(SystemResource.class));
- parents.removeFirst();
- // Directories at the 'bottom'
- parents.forEach(resource -> assertThat(resource, instanceOf(DirectoryResource.class)));
- }
-
- @Test
- public void shouldCreateFileResource() {
- // A file schema uri for a file should return a FileResource
- // The parents of this FileResource should be zero or more DirectoryResources up-to a root SystemResource
- // eg. "file:/dev/Palisade-common/pom.xml" = System "/" -> Directory "/dev/" -> Directory "/dev/Palisade-common/" -> File "/dev/Palisade-common/pom.xml"
-
- // Given
- final File pom = new File(System.getProperty("user.dir") + "/pom.xml");
-
- // When
- FileResource fileResource = (FileResource) ResourceBuilder.create(pom.toURI());
-
- // Then
- LinkedList parents = getAllParents(fileResource);
- // System at the 'top'
- assertThat(parents.getFirst(), instanceOf(SystemResource.class));
- parents.removeFirst();
- // File at the 'bottom'
- assertThat(parents.getLast(), instanceOf(FileResource.class));
- parents.removeLast();
- // Directories in the 'middle'
- parents.forEach(resource -> assertThat(resource, instanceOf(DirectoryResource.class)));
- }
-
- @Test
- public void shouldNormaliseRelativePaths() {
- // A file schema uri for a file with a relative path should return a FileResource with an absolute resource id
- // The parents of this FileResource should be zero or more DirectoryResources up-to a root SystemResource
- // eg. "file:/dev/Palisade-common/pom.xml" = System "/" -> Directory "/dev/" -> Directory "/dev/Palisade-common/" -> File "/dev/Palisade-common/pom.xml"
-
- // Given
- final URI absolutePom = new File(System.getProperty("user.dir") + "/pom.xml").toURI();
- final URI relativePom = UriBuilder.create(absolutePom)
- .withoutScheme()
- .withoutAuthority()
- .withPath(absolutePom.getPath() + "/../pom.xml")
- .withoutQuery()
- .withoutFragment();
-
- // When
- FileResource relativeFile = (FileResource) ResourceBuilder.create(relativePom);
- FileResource absoluteFile = (FileResource) ResourceBuilder.create(absolutePom);
-
- // Then
- assertThat(relativeFile, equalTo(absoluteFile));
- }
-
- private LinkedList getAllParents(final Resource resource) {
- if (resource instanceof ChildResource) {
- final LinkedList parents = getAllParents(((ChildResource) resource).getParent());
- parents.addLast(resource);
- return parents;
- } else {
- return new LinkedList<>(Collections.singleton(resource));
- }
- }
-}
diff --git a/src/test/java/uk/gov/gchq/palisade/util/TestUtil.java b/src/test/java/uk/gov/gchq/palisade/util/TestUtil.java
deleted file mode 100644
index 48f8a026..00000000
--- a/src/test/java/uk/gov/gchq/palisade/util/TestUtil.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-public class TestUtil {
- private static final Logger LOGGER = LoggerFactory.getLogger(TestUtil.class);
-
- public static final File TMP_DIRECTORY;
-
- static {
- final String tmpDirectoryProperty = System.getProperty("java.io.tmpdir");
-
- if (null != tmpDirectoryProperty) {
- TMP_DIRECTORY = new File(tmpDirectoryProperty);
- } else {
- LOGGER.warn("Could not determine default temporary directory, using current directory.");
- TMP_DIRECTORY = new File(".");
- }
- }
-
- /**
- * Compare two streams for equality. Each stream must be of the same length and contain the same elements (by
- * value). The streams are sorted beforehand. Therefore T must be naturally comparable.
- *
- * @param expected first stream
- * @param actual second stream
- * @param type of list element
- * @return true if streams are equal
- */
- public static boolean streamEqual(final Stream extends T> expected, final Stream extends T> actual) {
- Stream extends T> sortExpected = expected.sorted();
- Stream extends T> sortActual = actual.sorted();
- List extends T> lhs = sortExpected.collect(Collectors.toList());
- List extends T> rhs = sortActual.collect(Collectors.toList());
- return lhs.equals(rhs);
- }
-}
diff --git a/src/test/resources/avro/testObj.avsc b/src/test/resources/avro/testObj.avsc
deleted file mode 100644
index 51e3ebd5..00000000
--- a/src/test/resources/avro/testObj.avsc
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "namespace": "uk.gov.gchq.palisade.data.service.impl.serialiser",
- "type": "record",
- "name": "TestObj",
- "fields": [
- {
- "name": "fieldStr1",
- "type": "string"
- },
- {
- "name": "fieldInt",
- "type": [
- "int",
- "null"
- ]
- },
- {
- "name": "fieldStr2",
- "type": [
- "string",
- "null"
- ]
- }
- ]
-}
From 2a4bea740dd224bb626f666e95895b09d3973455 Mon Sep 17 00:00:00 2001
From: dev930018 <56113485+dev930018@users.noreply.github.com>
Date: Tue, 20 Apr 2021 14:56:36 +0100
Subject: [PATCH 20/27] Pal 1043 fix common json serialisation (#89)
* PAL-1043-fix-common-json-serialisation initial commit
* PAL-1043 always use standard @class for json classpath
---
mvn_dependency_tree.txt | 22 +++------
pom.xml | 49 -------------------
.../java/uk/gov/gchq/palisade/Context.java | 15 +-----
.../palisade/data/serialise/Serialiser.java | 5 --
.../palisade/resource/ConnectionDetail.java | 23 +--------
.../gov/gchq/palisade/resource/Resource.java | 24 +--------
.../java/uk/gov/gchq/palisade/rule/Rule.java | 20 +-------
.../java/uk/gov/gchq/palisade/rule/Rules.java | 3 --
.../java/uk/gov/gchq/palisade/user/User.java | 13 +----
9 files changed, 13 insertions(+), 161 deletions(-)
diff --git a/mvn_dependency_tree.txt b/mvn_dependency_tree.txt
index b5f443db..416c60cf 100644
--- a/mvn_dependency_tree.txt
+++ b/mvn_dependency_tree.txt
@@ -2,17 +2,11 @@ uk.gov.gchq.palisade:common:jar:0.5.0-SNAPSHOT
+- com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:compile
| +- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.0:compile
| \- com.fasterxml.jackson.core:jackson-core:jar:2.10.0:compile
-+- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.10.0:compile
-+- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.10.0:compile
-+- commons-io:commons-io:jar:2.6:compile
-+- org.apache.commons:commons-lang3:jar:3.8.1:compile
-+- org.slf4j:slf4j-api:jar:1.7.25:compile
-+- org.apache.avro:avro:jar:1.8.2:compile
-| +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
-| +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
-| +- com.thoughtworks.paranamer:paranamer:jar:2.7:compile
-| +- org.xerial.snappy:snappy-java:jar:1.1.1.3:compile
-| +- org.apache.commons:commons-compress:jar:1.8.1:compile
-| \- org.tukaani:xz:jar:1.5:compile
-\- junit:junit:jar:4.13.1:test
- \- org.hamcrest:hamcrest-core:jar:1.3:test
+\- org.apache.avro:avro:jar:1.8.2:compile
+ +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
+ +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
+ +- com.thoughtworks.paranamer:paranamer:jar:2.7:compile
+ +- org.xerial.snappy:snappy-java:jar:1.1.1.3:compile
+ +- org.apache.commons:commons-compress:jar:1.8.1:compile
+ +- org.tukaani:xz:jar:1.5:compile
+ \- org.slf4j:slf4j-api:jar:1.7.7:compile
diff --git a/pom.xml b/pom.xml
index 76c88c36..d1f7cdf1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -97,44 +97,6 @@
jackson-databind${jackson.version}
-
-
- com.fasterxml.jackson.datatype
- jackson-datatype-jdk8
- ${jackson.version}
-
-
-
- com.fasterxml.jackson.datatype
- jackson-datatype-jsr310
- ${jackson.version}
-
-
-
-
-
- commons-io
- commons-io
- ${commons-io.version}
-
-
-
- org.apache.commons
- commons-lang3
- ${commons-lang3.version}
-
-
-
-
-
- org.slf4j
- slf4j-api
- ${slf4j.api.version}
-
@@ -142,17 +104,6 @@
avro${avro.version}
-
-
-
-
- junit
- junit
- ${junit.version}
- test
-
diff --git a/src/main/java/uk/gov/gchq/palisade/Context.java b/src/main/java/uk/gov/gchq/palisade/Context.java
index a06e0ed4..233d575f 100644
--- a/src/main/java/uk/gov/gchq/palisade/Context.java
+++ b/src/main/java/uk/gov/gchq/palisade/Context.java
@@ -17,10 +17,8 @@
package uk.gov.gchq.palisade;
import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import java.util.Collections;
@@ -37,12 +35,7 @@
* additional information that can be stored and recovered in this structure and passed along with the request/operation.
* i.e. A users purpose for requesting the contents of a file.
*/
-@JsonPropertyOrder(value = {"class", "contents"}, alphabetic = true)
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.CLASS,
- include = JsonTypeInfo.As.EXISTING_PROPERTY,
- property = "class"
-)
+@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public class Context {
private static final String PURPOSE = "purpose";
@@ -179,12 +172,6 @@ public Context putIfAbsent(final String key, final Object value) {
return this;
}
- @JsonGetter("class")
- @Generated
- public String getClassName() {
- return getClass().getName();
- }
-
@Override
@Generated
public boolean equals(final Object o) {
diff --git a/src/main/java/uk/gov/gchq/palisade/data/serialise/Serialiser.java b/src/main/java/uk/gov/gchq/palisade/data/serialise/Serialiser.java
index bf59ee9f..63deb6dd 100644
--- a/src/main/java/uk/gov/gchq/palisade/data/serialise/Serialiser.java
+++ b/src/main/java/uk/gov/gchq/palisade/data/serialise/Serialiser.java
@@ -15,20 +15,15 @@
*/
package uk.gov.gchq.palisade.data.serialise;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.stream.Stream;
-@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = As.EXISTING_PROPERTY, property = "class")
/**
* Serialisers are the part of Palisade that convert from a particular data serialised format to a stream of objects
* and back again.
- *
* IMPORTANT: All instances of this interface must be thread safe. That is, they must support multiple threads performing
* calling either {@link Serialiser#deserialise(InputStream)} or {@link Serialiser#serialise(Stream, OutputStream)} concurrently.
* The easiest and recommended way to do this is to make the {@code Serialiser} instance stateless; don't store anything related to
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/ConnectionDetail.java b/src/main/java/uk/gov/gchq/palisade/resource/ConnectionDetail.java
index 744873b9..d3092477 100644
--- a/src/main/java/uk/gov/gchq/palisade/resource/ConnectionDetail.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/ConnectionDetail.java
@@ -16,37 +16,16 @@
package uk.gov.gchq.palisade.resource;
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
-
-import uk.gov.gchq.palisade.resource.impl.SimpleConnectionDetail;
import java.io.Serializable;
/**
* A High level API for passing details of how to connect to a resource
*/
-@JsonPropertyOrder(value = {"class", "host", "port"}, alphabetic = true)
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.CLASS,
- include = As.EXISTING_PROPERTY,
- property = "class",
- defaultImpl = SimpleConnectionDetail.class
-)
+@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public interface ConnectionDetail extends Serializable {
String createConnection();
- @JsonGetter("class")
- default String getClassName() {
- return getClass().getName();
- }
-
- @JsonSetter("class")
- default void setClassName(final String className) {
- // do nothing.
- }
}
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/Resource.java b/src/main/java/uk/gov/gchq/palisade/resource/Resource.java
index befded71..4a3c17af 100644
--- a/src/main/java/uk/gov/gchq/palisade/resource/Resource.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/Resource.java
@@ -16,13 +16,7 @@
package uk.gov.gchq.palisade.resource;
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
-
-import uk.gov.gchq.palisade.resource.impl.FileResource;
import java.io.Serializable;
@@ -30,13 +24,7 @@
* A high level API to define a resource, where a resource could be a system, directory, file, stream, etc.
* A resource is expected to have a unique identifier.
*/
-@JsonPropertyOrder(value = {"class", "id"}, alphabetic = true)
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.CLASS,
- include = As.EXISTING_PROPERTY,
- property = "class",
- defaultImpl = FileResource.class
-)
+@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public interface Resource extends Comparable, Serializable {
Resource id(String id);
@@ -45,14 +33,4 @@ public interface Resource extends Comparable, Serializable {
void setId(final String id);
- @JsonGetter("class")
- default String getClassName() {
- return getClass().getName();
- }
-
- @JsonSetter("class")
- default void setClassName(final String className) {
- // do nothing.
- }
-
}
diff --git a/src/main/java/uk/gov/gchq/palisade/rule/Rule.java b/src/main/java/uk/gov/gchq/palisade/rule/Rule.java
index bae99d9b..4f8d8d55 100644
--- a/src/main/java/uk/gov/gchq/palisade/rule/Rule.java
+++ b/src/main/java/uk/gov/gchq/palisade/rule/Rule.java
@@ -15,11 +15,7 @@
*/
package uk.gov.gchq.palisade.rule;
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import uk.gov.gchq.palisade.Context;
import uk.gov.gchq.palisade.user.User;
@@ -44,12 +40,7 @@
* by the record reader before being passed to the apply(T, User, Context) method.
*/
@FunctionalInterface
-@JsonPropertyOrder(value = {"class"}, alphabetic = true)
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.CLASS,
- include = As.EXISTING_PROPERTY,
- property = "class"
-)
+@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public interface Rule extends Serializable {
/**
* Applies the rule logic to redact or modify the record based on the user and context.
@@ -74,13 +65,4 @@ default boolean isApplicable(final User user, final Context context) {
return true;
}
- @JsonGetter("class")
- default String getClassName() {
- return getClass().getName();
- }
-
- @JsonSetter("class")
- default void setClassName(final String className) {
- // do nothing.
- }
}
diff --git a/src/main/java/uk/gov/gchq/palisade/rule/Rules.java b/src/main/java/uk/gov/gchq/palisade/rule/Rules.java
index 9754bb86..1ee9d789 100644
--- a/src/main/java/uk/gov/gchq/palisade/rule/Rules.java
+++ b/src/main/java/uk/gov/gchq/palisade/rule/Rules.java
@@ -16,8 +16,6 @@
package uk.gov.gchq.palisade.rule;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-
import uk.gov.gchq.palisade.Generated;
import java.io.Serializable;
@@ -37,7 +35,6 @@
*
* @param The type of data records that the rules will be applied to.
*/
-@JsonPropertyOrder(value = {"message", "rules"}, alphabetic = true)
public class Rules implements Serializable {
private static final long serialVersionUID = 1L;
private static final String ID_CANNOT_BE_NULL = "The id field can not be null.";
diff --git a/src/main/java/uk/gov/gchq/palisade/user/User.java b/src/main/java/uk/gov/gchq/palisade/user/User.java
index bab456d4..4061abb2 100644
--- a/src/main/java/uk/gov/gchq/palisade/user/User.java
+++ b/src/main/java/uk/gov/gchq/palisade/user/User.java
@@ -16,7 +16,6 @@
package uk.gov.gchq.palisade.user;
-import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import uk.gov.gchq.palisade.Generated;
@@ -42,11 +41,7 @@
* The user auths are used specifically to decide what visibilities users can see.
*
*/
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.CLASS,
- include = JsonTypeInfo.As.EXISTING_PROPERTY,
- property = "class"
-)
+@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@@ -193,12 +188,6 @@ public void setAuths(final Set auths) {
this.auths = auths;
}
- @JsonGetter("class")
- @Generated
- public String getClassName() {
- return getClass().getName();
- }
-
@Override
@Generated
public boolean equals(final Object o) {
From 23e868149d0149235420ba3d001c68683f819a03 Mon Sep 17 00:00:00 2001
From: pd104923 <54805408+pd104923@users.noreply.github.com>
Date: Tue, 11 May 2021 17:50:11 +0100
Subject: [PATCH 21/27] PAL-1044 updated jackson dependency (#92)
---
mvn_dependency_tree.txt | 6 +++---
pom.xml | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/mvn_dependency_tree.txt b/mvn_dependency_tree.txt
index 416c60cf..00ffaf28 100644
--- a/mvn_dependency_tree.txt
+++ b/mvn_dependency_tree.txt
@@ -1,7 +1,7 @@
uk.gov.gchq.palisade:common:jar:0.5.0-SNAPSHOT
-+- com.fasterxml.jackson.core:jackson-databind:jar:2.10.0:compile
-| +- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.0:compile
-| \- com.fasterxml.jackson.core:jackson-core:jar:2.10.0:compile
++- com.fasterxml.jackson.core:jackson-databind:jar:2.11.0:compile
+| +- com.fasterxml.jackson.core:jackson-annotations:jar:2.11.0:compile
+| \- com.fasterxml.jackson.core:jackson-core:jar:2.11.0:compile
\- org.apache.avro:avro:jar:1.8.2:compile
+- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
+- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
diff --git a/pom.xml b/pom.xml
index d1f7cdf1..a0c7cf95 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,7 +53,7 @@
3.1.03.8.01.7.25
- 2.10.0
+ 2.11.02.63.8.11.8.2
From 07d803eba9d85b0c45e4373d3deb5332f0b9c3bc Mon Sep 17 00:00:00 2001
From: dev930018 <56113485+dev930018@users.noreply.github.com>
Date: Mon, 17 May 2021 13:33:41 +0100
Subject: [PATCH 22/27] Pal 1040 push to public nexus (#91)
---
.gitignore | 2 +
NOTICES.md | 16 +-
licenses/eclipse_public_license_1.0.html | 261 ----------------
licenses/mit_license.html | 372 -----------------------
pom.xml | 191 +++++++++---
5 files changed, 147 insertions(+), 695 deletions(-)
delete mode 100644 licenses/eclipse_public_license_1.0.html
delete mode 100644 licenses/mit_license.html
diff --git a/.gitignore b/.gitignore
index f6c6cbf1..8a1133f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,8 @@ node_modules/
.project
.settings
*.iml
+*.DS_Store
+.flattened-pom.xml
##VSCODE default files that dont need to be tracked
.vscode/
diff --git a/NOTICES.md b/NOTICES.md
index 8c625723..52b0b323 100644
--- a/NOTICES.md
+++ b/NOTICES.md
@@ -1,19 +1,5 @@
List of third-party dependencies grouped by their license type
### [Apache Software License 2.0](./licenses/apache_software_license_2.0.txt):
-* Jackson-annotations ([com.fasterxml.jackson.core:jackson-annotations:2.10.0](http://github.com/FasterXML/jackson))
-* Jackson-core ([com.fasterxml.jackson.core:jackson-core:2.10.0](https://github.com/FasterXML/jackson-core))
-* jackson-databind ([com.fasterxml.jackson.core:jackson-databind:2.10.0](http://github.com/FasterXML/jackson))
-* Jackson datatype: jdk8 ([com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.10.0](https://github.com/FasterXML/jackson-modules-java8/jackson-datatype-jdk8))
-* Jackson datatype: JSR310 ([com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.0](https://github.com/FasterXML/jackson-modules-java8/jackson-datatype-jsr310))
-* Apache Commons IO ([commons-io:commons-io:2.6](http://commons.apache.org/proper/commons-io/))
+* jackson-databind ([com.fasterxml.jackson.core:jackson-databind:2.11.0](http://github.com/FasterXML/jackson))
* Apache Avro ([org.apache.avro:avro:1.8.2](http://avro.apache.org))
-* Apache Commons Lang ([org.apache.commons:commons-lang3:3.8.1](http://commons.apache.org/proper/commons-lang/))
-* Commons Math ([org.apache.commons:commons-math3:3.1.1](http://commons.apache.org/math/))
-
-### [Eclipse Public License 1.0](./licenses/eclipse_public_license_1.0.html):
-* JUnit ([junit:junit:4.12](http://junit.org))
-
-### [MIT License](./licenses/mit_license.html):
-* mockito-core ([org.mockito:mockito-core:3.1.0](https://github.com/mockito/mockito))
-* SLF4J API Module ([org.slf4j:slf4j-api:1.7.25](http://www.slf4j.org))
diff --git a/licenses/eclipse_public_license_1.0.html b/licenses/eclipse_public_license_1.0.html
deleted file mode 100644
index 3998fceb..00000000
--- a/licenses/eclipse_public_license_1.0.html
+++ /dev/null
@@ -1,261 +0,0 @@
-
-
-
-
-
-
-Eclipse Public License - Version 1.0
-
-
-
-
-
-
-
Eclipse Public License - v 1.0
-
-
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
-PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
-DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
-AGREEMENT.
-
-
1. DEFINITIONS
-
-
"Contribution" means:
-
-
a) in the case of the initial Contributor, the initial
-code and documentation distributed under this Agreement, and
-
b) in the case of each subsequent Contributor:
-
i) changes to the Program, and
-
ii) additions to the Program;
-
where such changes and/or additions to the Program
-originate from and are distributed by that particular Contributor. A
-Contribution 'originates' from a Contributor if it was added to the
-Program by such Contributor itself or anyone acting on such
-Contributor's behalf. Contributions do not include additions to the
-Program which: (i) are separate modules of software distributed in
-conjunction with the Program under their own license agreement, and (ii)
-are not derivative works of the Program.
-
-
"Contributor" means any person or entity that distributes
-the Program.
-
-
"Licensed Patents" mean patent claims licensable by a
-Contributor which are necessarily infringed by the use or sale of its
-Contribution alone or when combined with the Program.
-
-
"Program" means the Contributions distributed in accordance
-with this Agreement.
-
-
"Recipient" means anyone who receives the Program under
-this Agreement, including all Contributors.
-
-
2. GRANT OF RIGHTS
-
-
a) Subject to the terms of this Agreement, each
-Contributor hereby grants Recipient a non-exclusive, worldwide,
-royalty-free copyright license to reproduce, prepare derivative works
-of, publicly display, publicly perform, distribute and sublicense the
-Contribution of such Contributor, if any, and such derivative works, in
-source code and object code form.
-
-
b) Subject to the terms of this Agreement, each
-Contributor hereby grants Recipient a non-exclusive, worldwide,
-royalty-free patent license under Licensed Patents to make, use, sell,
-offer to sell, import and otherwise transfer the Contribution of such
-Contributor, if any, in source code and object code form. This patent
-license shall apply to the combination of the Contribution and the
-Program if, at the time the Contribution is added by the Contributor,
-such addition of the Contribution causes such combination to be covered
-by the Licensed Patents. The patent license shall not apply to any other
-combinations which include the Contribution. No hardware per se is
-licensed hereunder.
-
-
c) Recipient understands that although each Contributor
-grants the licenses to its Contributions set forth herein, no assurances
-are provided by any Contributor that the Program does not infringe the
-patent or other intellectual property rights of any other entity. Each
-Contributor disclaims any liability to Recipient for claims brought by
-any other entity based on infringement of intellectual property rights
-or otherwise. As a condition to exercising the rights and licenses
-granted hereunder, each Recipient hereby assumes sole responsibility to
-secure any other intellectual property rights needed, if any. For
-example, if a third party patent license is required to allow Recipient
-to distribute the Program, it is Recipient's responsibility to acquire
-that license before distributing the Program.
-
-
d) Each Contributor represents that to its knowledge it
-has sufficient copyright rights in its Contribution, if any, to grant
-the copyright license set forth in this Agreement.
-
-
3. REQUIREMENTS
-
-
A Contributor may choose to distribute the Program in object code
-form under its own license agreement, provided that:
-
-
a) it complies with the terms and conditions of this
-Agreement; and
-
-
b) its license agreement:
-
-
i) effectively disclaims on behalf of all Contributors
-all warranties and conditions, express and implied, including warranties
-or conditions of title and non-infringement, and implied warranties or
-conditions of merchantability and fitness for a particular purpose;
-
-
ii) effectively excludes on behalf of all Contributors
-all liability for damages, including direct, indirect, special,
-incidental and consequential damages, such as lost profits;
-
-
iii) states that any provisions which differ from this
-Agreement are offered by that Contributor alone and not by any other
-party; and
-
-
iv) states that source code for the Program is available
-from such Contributor, and informs licensees how to obtain it in a
-reasonable manner on or through a medium customarily used for software
-exchange.
-
-
When the Program is made available in source code form:
-
-
a) it must be made available under this Agreement; and
-
-
b) a copy of this Agreement must be included with each
-copy of the Program.
-
-
Contributors may not remove or alter any copyright notices contained
-within the Program.
-
-
Each Contributor must identify itself as the originator of its
-Contribution, if any, in a manner that reasonably allows subsequent
-Recipients to identify the originator of the Contribution.
-
-
4. COMMERCIAL DISTRIBUTION
-
-
Commercial distributors of software may accept certain
-responsibilities with respect to end users, business partners and the
-like. While this license is intended to facilitate the commercial use of
-the Program, the Contributor who includes the Program in a commercial
-product offering should do so in a manner which does not create
-potential liability for other Contributors. Therefore, if a Contributor
-includes the Program in a commercial product offering, such Contributor
-("Commercial Contributor") hereby agrees to defend and
-indemnify every other Contributor ("Indemnified Contributor")
-against any losses, damages and costs (collectively "Losses")
-arising from claims, lawsuits and other legal actions brought by a third
-party against the Indemnified Contributor to the extent caused by the
-acts or omissions of such Commercial Contributor in connection with its
-distribution of the Program in a commercial product offering. The
-obligations in this section do not apply to any claims or Losses
-relating to any actual or alleged intellectual property infringement. In
-order to qualify, an Indemnified Contributor must: a) promptly notify
-the Commercial Contributor in writing of such claim, and b) allow the
-Commercial Contributor to control, and cooperate with the Commercial
-Contributor in, the defense and any related settlement negotiations. The
-Indemnified Contributor may participate in any such claim at its own
-expense.
-
-
For example, a Contributor might include the Program in a commercial
-product offering, Product X. That Contributor is then a Commercial
-Contributor. If that Commercial Contributor then makes performance
-claims, or offers warranties related to Product X, those performance
-claims and warranties are such Commercial Contributor's responsibility
-alone. Under this section, the Commercial Contributor would have to
-defend claims against the other Contributors related to those
-performance claims and warranties, and if a court requires any other
-Contributor to pay any damages as a result, the Commercial Contributor
-must pay those damages.
-
-
5. NO WARRANTY
-
-
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
-PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
-OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
-ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
-OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
-responsible for determining the appropriateness of using and
-distributing the Program and assumes all risks associated with its
-exercise of rights under this Agreement , including but not limited to
-the risks and costs of program errors, compliance with applicable laws,
-damage to or loss of data, programs or equipment, and unavailability or
-interruption of operations.
-
-
6. DISCLAIMER OF LIABILITY
-
-
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
-NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
-WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
-DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
-HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
-
7. GENERAL
-
-
If any provision of this Agreement is invalid or unenforceable under
-applicable law, it shall not affect the validity or enforceability of
-the remainder of the terms of this Agreement, and without further action
-by the parties hereto, such provision shall be reformed to the minimum
-extent necessary to make such provision valid and enforceable.
-
-
If Recipient institutes patent litigation against any entity
-(including a cross-claim or counterclaim in a lawsuit) alleging that the
-Program itself (excluding combinations of the Program with other
-software or hardware) infringes such Recipient's patent(s), then such
-Recipient's rights granted under Section 2(b) shall terminate as of the
-date such litigation is filed.
-
-
All Recipient's rights under this Agreement shall terminate if it
-fails to comply with any of the material terms or conditions of this
-Agreement and does not cure such failure in a reasonable period of time
-after becoming aware of such noncompliance. If all Recipient's rights
-under this Agreement terminate, Recipient agrees to cease use and
-distribution of the Program as soon as reasonably practicable. However,
-Recipient's obligations under this Agreement and any licenses granted by
-Recipient relating to the Program shall continue and survive.
-
-
Everyone is permitted to copy and distribute copies of this
-Agreement, but in order to avoid inconsistency the Agreement is
-copyrighted and may only be modified in the following manner. The
-Agreement Steward reserves the right to publish new versions (including
-revisions) of this Agreement from time to time. No one other than the
-Agreement Steward has the right to modify this Agreement. The Eclipse
-Foundation is the initial Agreement Steward. The Eclipse Foundation may
-assign the responsibility to serve as the Agreement Steward to a
-suitable separate entity. Each new version of the Agreement will be
-given a distinguishing version number. The Program (including
-Contributions) may always be distributed subject to the version of the
-Agreement under which it was received. In addition, after a new version
-of the Agreement is published, Contributor may elect to distribute the
-Program (including its Contributions) under the new version. Except as
-expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
-rights or licenses to the intellectual property of any Contributor under
-this Agreement, whether expressly, by implication, estoppel or
-otherwise. All rights in the Program not expressly granted under this
-Agreement are reserved.
-
-
This Agreement is governed by the laws of the State of New York and
-the intellectual property laws of the United States of America. No party
-to this Agreement will bring a legal action under this Agreement more
-than one year after the cause of action arose. Each party waives its
-rights to a jury trial in any resulting litigation.
-
-
-
-
\ No newline at end of file
diff --git a/licenses/mit_license.html b/licenses/mit_license.html
deleted file mode 100644
index 77f6583b..00000000
--- a/licenses/mit_license.html
+++ /dev/null
@@ -1,372 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
- The MIT License | Open Source Initiative
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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.
-
-
-
-End license text.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index a0c7cf95..762766d9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,13 +14,17 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+4.0.0
+
uk.gov.gchq.palisadecommon0.5.0-${revision}
- Palisade common code
+ Palisade common data-types shared between multiple serviceshttps://github.com/gchq/Palisade-common
+ GCHQ Palisade Common Library
@@ -33,12 +37,19 @@
Apache License, Version 2.0
- http://www.apache.org/licenses/LICENSE-2.0.txt
+ https://www.apache.org/licenses/LICENSE-2.0.txt
+
+ ${scm.url}
+ ${scm.connection}
+ ${scm.developer.connection}
+ HEAD
+
+
-
+
11SNAPSHOT${java.version}
@@ -48,10 +59,21 @@
${encoding}
- 3.1.0
+ 3.8.03.1.2
+ 3.1.03.1.03.8.0
+
+
+ 1.5
+ 1.6.8
+ 2.5.3
+ 1.1
+ 3.2.1
+
+
+ 2.10.01.7.252.11.02.6
@@ -59,31 +81,35 @@
1.8.2
- 4.13.1
- 2.22.1
- 2.22.13.1.0
+ true
-
+
jacocoreuseReports${project.basedir}/../target/site/jacoco/jacoco.xmljava
+
+
+ https://github.com/gchq/Palisade-common
+ scm:git:https://github.com/gchq/Palisade-common.git
+ scm:git:https://github.com/gchq/Palisade-common.git
-
- nexus
- releases
- ${release.url}
+ ${releases.repository.id}
+ ${releases.repository.name}
+
+ ${releases.repository.url}
-
- nexus
- snapshots
- ${snapshot.url}
+ ${snapshots.repository.id}
+ false
+ ${snapshots.repository.name}
+
+ ${snapshots.repository.url}
@@ -114,7 +140,6 @@
truetruetrue
- truetruetrue
@@ -146,6 +171,78 @@
+
+ release
+
+
+ ossrh
+ Sonatype Nexus release repository
+ https://oss.sonatype.org/service/local/staging/deploy/maven2/
+ ossrh
+ Sonatype Nexus snapshot repository
+ https://oss.sonatype.org/content/repositories/snapshots
+ RELEASE
+ true
+
+
+
+
+ org.sonatype.plugins
+ nexus-staging-maven-plugin
+ ${nexus.plugin.version}
+ true
+
+ ${releases.repository.id}
+ https://oss.sonatype.org/
+ false
+ true
+
+ 10
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ ${source.plugin.version}
+
+
+ attach-sources
+
+ jar-no-fork
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ ${javadoc.plugin.version}
+
+
+ attach-javadocs
+
+ jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+ ${gpg.plugin.version}
+
+
+ sign-artifacts
+ verify
+
+ sign
+
+
+
+
+
+
+
@@ -221,12 +318,6 @@
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- ${surefire.plugin.version}
- org.apache.maven.plugins
@@ -245,6 +336,31 @@
+
+ org.codehaus.mojo
+ flatten-maven-plugin
+ 1.1.0
+
+ true
+ ossrh
+
+
+
+ flatten
+ process-resources
+
+ flatten
+
+
+
+ flatten.clean
+ clean
+
+ clean
+
+
+
+ org.codehaus.mojo
@@ -255,8 +371,8 @@
licenses-reportprepare-package
- aggregate-download-licenses
- aggregate-add-third-party
+ download-licenses
+ add-third-party
@@ -353,32 +469,18 @@
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- ${jar.plugin.version}
-
-
-
- test-jar
-
-
-
- org.apache.maven.pluginsmaven-checkstyle-plugin${checkstyle.plugin.version}
- true
+ falsecode-style/checkstyle.xmlUTF-8truetrue
- code-style/licenseHeader.txt
-
+ code-style/licenseHeader.txtcode-style/checkstyle-suppressions.xmlcheckstyle.suppressions.file
@@ -392,11 +494,6 @@
-
- org.apache.maven.plugins
- maven-failsafe-plugin
- ${failsafe.version}
-
From dadfa771b51d2a6448c27f07ca4dcefc3e2be4c0 Mon Sep 17 00:00:00 2001
From: developer01189998819991197253
<52958809+developer01189998819991197253@users.noreply.github.com>
Date: Tue, 18 May 2021 14:55:22 +0100
Subject: [PATCH 23/27] Pal 1021 s3 resource service (#93)
---
.../resource/AbstractLeafResource.java | 21 +-
.../gchq/palisade/resource/LeafResource.java | 31 ++
.../palisade/resource/impl/FileResource.java | 5 +-
.../palisade/util/FileResourceBuilder.java | 114 +++++++
.../gchq/palisade/util/ResourceBuilder.java | 317 ++++++------------
.../uk.gov.gchq.palisade.util.ResourceBuilder | 1 +
6 files changed, 259 insertions(+), 230 deletions(-)
create mode 100644 src/main/java/uk/gov/gchq/palisade/util/FileResourceBuilder.java
create mode 100644 src/main/resources/META-INF/services/uk.gov.gchq.palisade.util.ResourceBuilder
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/AbstractLeafResource.java b/src/main/java/uk/gov/gchq/palisade/resource/AbstractLeafResource.java
index fa4df52e..399c00ce 100644
--- a/src/main/java/uk/gov/gchq/palisade/resource/AbstractLeafResource.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/AbstractLeafResource.java
@@ -19,7 +19,6 @@
import uk.gov.gchq.palisade.Generated;
import uk.gov.gchq.palisade.resource.impl.FileResource;
-import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -39,9 +38,9 @@ public abstract class AbstractLeafResource extends AbstractResource implements L
private String serialisedFormat;
private ConnectionDetail connectionDetail;
private ParentResource parent;
- private HashMap attributes = new HashMap<>();
+ private HashMap attributes = new HashMap<>();
- public AbstractLeafResource() {
+ protected AbstractLeafResource() {
}
@Generated
@@ -65,11 +64,11 @@ public AbstractLeafResource connectionDetail(final ConnectionDetail connectionDe
/**
* Sets the attributes for the {@link AbstractLeafResource}
*
- * @param attributes a {@link Map} of {@link String} and {@link Serializable}.
+ * @param attributes a {@link Map} of {@link String} keys and {@link String} values.
* @return a {@link AbstractLeafResource} object.
*/
@Generated
- public AbstractLeafResource attributes(final Map attributes) {
+ public AbstractLeafResource attributes(final Map attributes) {
this.setAttributes(attributes);
return this;
}
@@ -78,11 +77,11 @@ public AbstractLeafResource attributes(final Map attribute
* Sets the attributes for the {@link AbstractLeafResource}
*
* @param attributeKey a {@link String} value for the key.
- * @param attributeValue a {@link Serializable} value
+ * @param attributeValue a {@link String} value
* @return the {@link AbstractLeafResource} object
*/
@Generated
- public AbstractLeafResource attribute(final String attributeKey, final Serializable attributeValue) {
+ public AbstractLeafResource attribute(final String attributeKey, final String attributeValue) {
this.setAttribute(attributeKey, attributeValue);
return this;
}
@@ -146,12 +145,12 @@ public void setParent(final ParentResource parent) {
}
@Generated
- public Map getAttributes() {
+ public Map getAttributes() {
return attributes;
}
@Generated
- public void setAttributes(final Map attributes) {
+ public void setAttributes(final Map attributes) {
requireNonNull(attributes);
this.attributes = new HashMap<>(attributes);
}
@@ -170,10 +169,10 @@ public Boolean isAttributeSet(final String attributeKey) {
* Sets the key and value of the attributes {@link Map} for the {@link AbstractLeafResource}
*
* @param attributeKey a {@link String} value for the attribute key.
- * @param attributeValue a {@link Serializable} value for the attribute value.
+ * @param attributeValue a {@link String} value for the attribute value.
*/
@Generated
- public void setAttribute(final String attributeKey, final Serializable attributeValue) {
+ public void setAttribute(final String attributeKey, final String attributeValue) {
requireNonNull(attributeKey, "The attributeKey cannot be set to null.");
requireNonNull(attributeKey, "The attributeValue cannot be set to null.");
this.attributes.put(attributeKey, attributeValue);
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/LeafResource.java b/src/main/java/uk/gov/gchq/palisade/resource/LeafResource.java
index 267dabca..dd1d7eb4 100644
--- a/src/main/java/uk/gov/gchq/palisade/resource/LeafResource.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/LeafResource.java
@@ -16,6 +16,8 @@
package uk.gov.gchq.palisade.resource;
+import java.util.Map;
+
/**
* A leaf resource is the interface for any resource that can be read for data
* and is not just part of the hierarchical resource structure.
@@ -25,12 +27,38 @@
public interface LeafResource extends ChildResource {
+ /**
+ * The type of resource, used for grouping data of the same structure
+ *
+ * @param type the type of resource
+ * @return a LeafResource with type attached
+ */
LeafResource type(final String type);
+ /**
+ * The format of the resource, e.g CSV, txt
+ *
+ * @param serialisedFormat the format of resource
+ * @return a LeafResource with format attached
+ */
LeafResource serialisedFormat(final String serialisedFormat);
+ /**
+ * The service where the LeafResource is stored. Used by the Data Service to connect to the correct service
+ *
+ * @param connectionDetail the location of the LeafResource
+ * @return a LeafResource with connectionDetail attached
+ */
LeafResource connectionDetail(final ConnectionDetail connectionDetail);
+ /**
+ * Any additional Attributes about the LeafResource
+ *
+ * @param attributes additional attributes or metadata about the LeafResource
+ * @return a LeafResource with attributes attached
+ */
+ LeafResource attributes(final Map attributes);
+
String getType();
String getSerialisedFormat();
@@ -43,4 +71,7 @@ public interface LeafResource extends ChildResource {
void setConnectionDetail(final ConnectionDetail connectionDetail);
+ Map getAttributes();
+
+ void setAttributes(Map attributes);
}
diff --git a/src/main/java/uk/gov/gchq/palisade/resource/impl/FileResource.java b/src/main/java/uk/gov/gchq/palisade/resource/impl/FileResource.java
index 4ac3cc80..5a646b3a 100644
--- a/src/main/java/uk/gov/gchq/palisade/resource/impl/FileResource.java
+++ b/src/main/java/uk/gov/gchq/palisade/resource/impl/FileResource.java
@@ -20,7 +20,6 @@
import uk.gov.gchq.palisade.resource.ConnectionDetail;
import uk.gov.gchq.palisade.resource.ParentResource;
-import java.io.Serializable;
import java.util.Map;
/**
@@ -55,12 +54,12 @@ public FileResource connectionDetail(final ConnectionDetail connectionDetail) {
}
@Override
- public FileResource attributes(final Map attributes) {
+ public FileResource attributes(final Map attributes) {
return (FileResource) super.attributes(attributes);
}
@Override
- public FileResource attribute(final String attributeKey, final Serializable attributeValue) {
+ public FileResource attribute(final String attributeKey, final String attributeValue) {
return (FileResource) super.attribute(attributeKey, attributeValue);
}
diff --git a/src/main/java/uk/gov/gchq/palisade/util/FileResourceBuilder.java b/src/main/java/uk/gov/gchq/palisade/util/FileResourceBuilder.java
new file mode 100644
index 00000000..3f306a3f
--- /dev/null
+++ b/src/main/java/uk/gov/gchq/palisade/util/FileResourceBuilder.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2018-2021 Crown Copyright
+ *
+ * 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.
+ */
+
+package uk.gov.gchq.palisade.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import uk.gov.gchq.palisade.resource.ParentResource;
+import uk.gov.gchq.palisade.resource.Resource;
+import uk.gov.gchq.palisade.resource.impl.DirectoryResource;
+import uk.gov.gchq.palisade.resource.impl.FileResource;
+import uk.gov.gchq.palisade.resource.impl.SystemResource;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Path;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Provides a common set of utilities for constructing resources with all parents
+ * automatically constructed recursively. This primarily targets filesystem-like
+ * resources (Files, Directories etc.)
+ * Internally, the resourceId is converted to a URI.
+ * Can produce any of the following output types:
+ * - {@link FileResource}
+ * - {@link DirectoryResource}
+ * - {@link SystemResource}
+ * Any parents automatically constructed will also be from this collection.
+ * If another method of creating a resource is required (i.e. directly using strings)
+ * there is no guarantee that this can correctly resolve parents. Instead, use the
+ * methods provided by the appropriate resource impl.
+ */
+public class FileResourceBuilder extends ResourceBuilder {
+ private static final Logger LOGGER = LoggerFactory.getLogger(FileResourceBuilder.class);
+ private static final URI ROOT;
+ private static final Set ACCEPTED_SCHEMES = Set.of("hdfs", "file");
+
+ public FileResourceBuilder() {
+ // Empty Constructor
+ }
+
+ static {
+ File userDir = new File(System.getProperty("user.dir"));
+ URI root;
+ try {
+ root = userDir.getCanonicalFile().toURI();
+ } catch (IOException ex) {
+ LOGGER.error("Failed to get canonical file for {}", userDir, ex);
+ root = userDir.getAbsoluteFile().toURI();
+ }
+ ROOT = root;
+ }
+
+ private static FileResource fileResource(final URI uri) {
+ return new FileResource()
+ .id(uri.normalize().toString())
+ .parent((ParentResource) filesystemScheme(uri.resolve(".")));
+ }
+
+ private static DirectoryResource directoryResource(final URI uri) {
+ return new DirectoryResource()
+ .id(uri.normalize().toString())
+ .parent((ParentResource) filesystemScheme(uri.resolve("..")));
+ }
+
+ private static SystemResource systemResource(final URI uri) {
+ return new SystemResource()
+ .id(uri.normalize().toString());
+ }
+
+ private static Resource filesystemScheme(final URI uri) {
+ // If passed relative paths, we can resolve them against the user.dir system property
+ URI absolute;
+ if (uri.isAbsolute()) {
+ absolute = uri;
+ } else {
+ absolute = ROOT.resolve(uri);
+ }
+ // Decide whether a File, Directory or System resource
+ if (!absolute.resolve(".").equals(absolute)) {
+ return fileResource(uri);
+ } else if (Objects.nonNull(Path.of(absolute).getParent())) {
+ return directoryResource(absolute);
+ } else {
+ return systemResource(absolute);
+ }
+ }
+
+ @Override
+ public Resource build(final URI resourceUri) {
+ return filesystemScheme(resourceUri);
+ }
+
+ @Override
+ public boolean accepts(final URI resourceUri) {
+ return ACCEPTED_SCHEMES.contains(resourceUri.getScheme());
+ }
+}
diff --git a/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java b/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java
index 43ec992b..cc36c4c3 100644
--- a/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java
+++ b/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java
@@ -1,216 +1,101 @@
-/*
- * Copyright 2018-2021 Crown Copyright
- *
- * 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.
- */
-
-package uk.gov.gchq.palisade.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import uk.gov.gchq.palisade.resource.ConnectionDetail;
-import uk.gov.gchq.palisade.resource.LeafResource;
-import uk.gov.gchq.palisade.resource.ParentResource;
-import uk.gov.gchq.palisade.resource.Resource;
-import uk.gov.gchq.palisade.resource.impl.DirectoryResource;
-import uk.gov.gchq.palisade.resource.impl.FileResource;
-import uk.gov.gchq.palisade.resource.impl.SystemResource;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.file.Path;
-import java.util.Collections;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Provides a common set of utilities for constructing resources with all parents
- * automatically constructed recursively. This primarily targets filesystem-like
- * resources (Files, Directories etc.)
- * Internally, the resourceId is converted to a URI.
- * Can produce any of the following output types:
- * - {@link FileResource}
- * - {@link DirectoryResource}
- * - {@link SystemResource}
- * Any parents automatically constructed will also be from this collection.
- * If another method of creating a resource is required (i.e. directly using strings)
- * there is no guarantee that this can correctly resolve parents. Instead, use the
- * methods provided by the appropriate resource impl.
- */
-public class ResourceBuilder {
- private static final Logger LOGGER = LoggerFactory.getLogger(ResourceBuilder.class);
- private static final URI ROOT;
-
- public ResourceBuilder() {
- // Empty Constructor
- }
-
- static {
- File userDir = new File(System.getProperty("user.dir"));
- URI root;
- try {
- root = userDir.getCanonicalFile().toURI();
- } catch (IOException ex) {
- LOGGER.error("ResourceBuilder threw an error when getting the CanonicalFile ", ex);
- root = userDir.getAbsoluteFile().toURI();
- }
- ROOT = root;
- }
-
- private enum Scheme {
- FILE,
- HDFS
- }
-
- /**
- * Create a leafResource from a uri, connectionDetail, type, serialisedFormat and attribute map
- * Throw IllegalArgumentException if unsupported scheme
- * Throw ClassCastException if uri did not point to a leaf resource
- *
- * @param uri the uri location of the resource
- * @param connectionDetail the service storing the resource
- * @param type the type of resource
- * @param serialisedFormat the format of the resource e.g avro, txt
- * @param attributes any additional attributes about the resource
- * @return a new LeafResource populated with these resources
- */
- public static LeafResource create(final URI uri, final ConnectionDetail connectionDetail, final String type, final String serialisedFormat, final Map attributes) {
- return ((LeafResource) create(uri, attributes))
- .connectionDetail(connectionDetail)
- .type(type)
- .serialisedFormat(serialisedFormat);
- }
-
- /**
- * Create a resource from a uri and attribute map
- * Throw IllegalArgumentException if unsupported scheme
- *
- * @param uri the id of the resource
- * @param attributes any additional attributes about the resource
- * @return a new resource created using this uri
- */
- public static Resource create(final URI uri, final Map attributes) {
- // If passed relative paths, we can resolve them against the user.dir system property
- URI absolute;
- if (uri.isAbsolute()) {
- absolute = uri;
- } else {
- absolute = ROOT.resolve(uri);
- }
- // The hostname is all in the connectionDetail, so we never have a case of file://hostname/some/uri
- // A lot of this is trying to normalize file:///some/uri (file:///some/uri) to file:/some/uri
- URI normal = UriBuilder.create(absolute)
- .withoutScheme()
- .withoutAuthority()
- .withoutPath()
- .withoutQuery()
- .withoutFragment();
-
- // This should be assigning the attributes map to the returned object, once resources support attribute maps
-
- switch (Scheme.valueOf(normal.getScheme().toUpperCase(Locale.ENGLISH))) {
- // Both file:/ and hdfs:/ schema produce filesystem-like structures
- case FILE:
- case HDFS:
- return filesystemSchema(normal);
- default:
- throw new IllegalArgumentException("No such implementation for uri scheme " + normal.getScheme());
- }
- }
-
- /**
- * Used to validate URIs and check that they can be created
- *
- * @param uri the uri to validate or attach to a resource
- * @return a boolean true/false if the uri scheme is valid.
- */
- public static boolean canCreate(final URI uri) {
- try {
- Scheme.valueOf(uri.getScheme()); // Or throw
- return uri.isAbsolute();
- } catch (IllegalArgumentException ex) {
- return false;
- }
- }
-
- /**
- * Create a resource from a uri
- * Default to an empty attribute map
- * Throw IllegalArgumentException if unsupported scheme
- *
- * @param uri an id of a resource
- * @return a newly created resource with an empty map of attributes
- */
- public static Resource create(final URI uri) {
- return create(uri, Collections.emptyMap());
- }
-
- /**
- * Create a resource from a uri string and attribute map
- * Throw IllegalArgumentException if invalid uri string or unsupported scheme
- *
- * @param uriString a string value of a url used to create a new resource
- * @param attributes any additional attributes about the resource
- * @return a newly created resource using these parameters
- */
- public static Resource create(final String uriString, final Map attributes) {
- try {
- return create(new URI(uriString), attributes);
- } catch (URISyntaxException ex) {
- throw new IllegalArgumentException("URISyntaxException converting string '" + uriString + "' to uri", ex);
- }
- }
-
- /**
- * Create a resource from a uri string
- * Default to an empty attribute map
- * Throw IllegalArgumentException if invalid uri string or unsupported scheme
- *
- * @param uriString a string value of a url used to create a new resource
- * @return a newly created resource with this url and an empty map of attributes
- */
- public static Resource create(final String uriString) {
- return create(uriString, Collections.emptyMap());
- }
-
- private static FileResource fileResource(final URI uri) {
- return new FileResource()
- .id(uri.normalize().toString())
- .parent((ParentResource) filesystemSchema(uri.resolve(".")));
- }
-
- private static DirectoryResource directoryResource(final URI uri) {
- return new DirectoryResource()
- .id(uri.normalize().toString())
- .parent((ParentResource) filesystemSchema(uri.resolve("..")));
- }
-
- private static SystemResource systemResource(final URI uri) {
- return new SystemResource()
- .id(uri.normalize().toString());
- }
-
- private static Resource filesystemSchema(final URI uri) {
- if (!uri.resolve(".").equals(uri)) {
- return fileResource(uri);
- } else if (Objects.nonNull(Path.of(uri).getParent())) {
- return directoryResource(uri);
- } else {
- return systemResource(uri);
- }
- }
-}
+/*
+ * Copyright 2018-2021 Crown Copyright
+ *
+ * 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.
+ */
+
+package uk.gov.gchq.palisade.util;
+
+import uk.gov.gchq.palisade.resource.Resource;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ServiceLoader;
+import java.util.ServiceLoader.Provider;
+
+/**
+ * ResourceBuilder, taking a URI and building a Resource specific to each scheme
+ */
+public abstract class ResourceBuilder {
+ private static final ServiceLoader LOADER = ServiceLoader.load(ResourceBuilder.class);
+
+ /**
+ * Clears this loader's provider cache so that all providers will be reloaded.
+ */
+ public static void refreshProviders() {
+ LOADER.reload();
+ }
+
+ /**
+ * Taking a resourceUri, create a resource using the ResourceBuilder provided in the LOADER,
+ * or throw an exception if the resource scheme is not supported, or no builder exists to build that scheme
+ *
+ * @param resourceUri the Uri of the resource you want to build.
+ * @return a newly created resource
+ */
+ public static Resource create(final URI resourceUri) {
+ ResourceBuilder resourceBuilder = LOADER.stream()
+ .map(Provider::get)
+ .filter(builder -> builder.accepts(resourceUri))
+ .findAny()
+ .orElseThrow(() -> new IllegalArgumentException("No ResourceBuilder found that accepts " + resourceUri));
+ return resourceBuilder.buildNormal(resourceUri);
+ }
+
+ /**
+ * Create a resource from a uri string
+ * Throw IllegalArgumentException if invalid uri string or unsupported scheme
+ *
+ * @param uriString a string value of a url used to create a new resource
+ * @return a newly created resource using these parameters.
+ */
+ public static Resource create(final String uriString) {
+ try {
+ return create(new URI(uriString));
+ } catch (URISyntaxException ex) {
+ throw new IllegalArgumentException("URISyntaxException converting string '" + uriString + "' to uri", ex);
+ }
+ }
+
+ /**
+ * Build a resource, using the uri provided by calling {@link UriBuilder}
+ *
+ * @param uri the uri of the resource you want built
+ * @return a newly created resource with the id of the uri.
+ */
+ public Resource buildNormal(final URI uri) {
+ URI normal = UriBuilder.create(uri)
+ .withoutScheme()
+ .withoutAuthority()
+ .withoutPath()
+ .withoutQuery()
+ .withoutFragment();
+ return build(normal);
+ }
+
+ /**
+ * An abstract method used in building a resource
+ *
+ * @param resourceUri the uri of the resource you want built
+ * @return a newly created Resource with the id of the the resourceUri.
+ */
+ protected abstract Resource build(URI resourceUri);
+
+ /**
+ * A abstract method used in building a resource, to check if the Builders provided can accept the resourceUri scheme
+ *
+ * @param resourceUri the uri of the resource you want built
+ * @return a true/false value if a builder exists that supports the uri scheme.
+ */
+ public abstract boolean accepts(URI resourceUri);
+}
diff --git a/src/main/resources/META-INF/services/uk.gov.gchq.palisade.util.ResourceBuilder b/src/main/resources/META-INF/services/uk.gov.gchq.palisade.util.ResourceBuilder
new file mode 100644
index 00000000..6dba381d
--- /dev/null
+++ b/src/main/resources/META-INF/services/uk.gov.gchq.palisade.util.ResourceBuilder
@@ -0,0 +1 @@
+uk.gov.gchq.palisade.util.FileResourceBuilder
\ No newline at end of file
From 34955e7aab8951e78a20ad43689bfae55ac3cbc1 Mon Sep 17 00:00:00 2001
From: pd104923 <54805408+pd104923@users.noreply.github.com>
Date: Wed, 26 May 2021 12:16:56 +0100
Subject: [PATCH 24/27] Pal 822 jvm example pipeline (#94)
* PAL-822 updated file resource builder
* PAL-822 refactored resource and file builder classes
* PAL-822 resolved sq smells
* PAL-822 removed unused import
* PAL-822 added inline comments, corrected minor spelling mistake
* Update src/main/java/uk/gov/gchq/palisade/util/FileResourceBuilder.java
Minor expansion to the inline comment
Co-authored-by: developer01189998819991197253 <52958809+developer01189998819991197253@users.noreply.github.com>
* PAL-822 refactored FileResourceBuilder
Co-authored-by: developer01189998819991197253 <52958809+developer01189998819991197253@users.noreply.github.com>
---
.../palisade/util/FileResourceBuilder.java | 24 ++++++++++++++++++-
.../gchq/palisade/util/ResourceBuilder.java | 23 ++++++++++++------
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/src/main/java/uk/gov/gchq/palisade/util/FileResourceBuilder.java b/src/main/java/uk/gov/gchq/palisade/util/FileResourceBuilder.java
index 3f306a3f..13085dd6 100644
--- a/src/main/java/uk/gov/gchq/palisade/util/FileResourceBuilder.java
+++ b/src/main/java/uk/gov/gchq/palisade/util/FileResourceBuilder.java
@@ -104,7 +104,29 @@ private static Resource filesystemScheme(final URI uri) {
@Override
public Resource build(final URI resourceUri) {
- return filesystemScheme(resourceUri);
+ URI absoluteResourceId = resourceUri;
+
+ // Check if the path is not complete, and therefore needs enriching to locate resources
+ if (!Path.of(resourceUri.getSchemeSpecificPart()).isAbsolute()) {
+ File localResource = new File(resourceUri.getSchemeSpecificPart());
+ String path;
+ try {
+ path = localResource.getCanonicalPath();
+ } catch (IOException e) {
+ LOGGER.warn("Unable to get the Canonical path value", e);
+ path = localResource.getAbsolutePath();
+ }
+
+ // Check if the resource is a directory and the path does not end with a "/"
+ if (localResource.isDirectory() && !path.endsWith("/")) {
+ path += "/";
+ }
+ absoluteResourceId = UriBuilder.create(resourceUri)
+ .withoutScheme().withoutAuthority()
+ .withPath(path)
+ .withoutQuery().withoutFragment();
+ }
+ return filesystemScheme(absoluteResourceId);
}
@Override
diff --git a/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java b/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java
index cc36c4c3..a05e1cd5 100644
--- a/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java
+++ b/src/main/java/uk/gov/gchq/palisade/util/ResourceBuilder.java
@@ -16,6 +16,9 @@
package uk.gov.gchq.palisade.util;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import uk.gov.gchq.palisade.resource.Resource;
import java.net.URI;
@@ -28,6 +31,7 @@
*/
public abstract class ResourceBuilder {
private static final ServiceLoader LOADER = ServiceLoader.load(ResourceBuilder.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(ResourceBuilder.class);
/**
* Clears this loader's provider cache so that all providers will be reloaded.
@@ -74,13 +78,18 @@ public static Resource create(final String uriString) {
* @return a newly created resource with the id of the uri.
*/
public Resource buildNormal(final URI uri) {
- URI normal = UriBuilder.create(uri)
- .withoutScheme()
- .withoutAuthority()
- .withoutPath()
- .withoutQuery()
- .withoutFragment();
- return build(normal);
+ try {
+ URI normal = UriBuilder.create(uri)
+ .withoutScheme()
+ .withoutAuthority()
+ .withoutPath()
+ .withoutQuery()
+ .withoutFragment();
+ return build(normal);
+ } catch (RuntimeException e) {
+ LOGGER.error("Unable to build a normal URI", e);
+ return build(uri);
+ }
}
/**
From fd8fad087775728fb343bd32091e01049e7054fe Mon Sep 17 00:00:00 2001
From: developer01189998819991197253
<52958809+developer01189998819991197253@users.noreply.github.com>
Date: Tue, 29 Jun 2021 16:58:01 +0100
Subject: [PATCH 25/27] PAL-1032 updated Palisade common readme (#96)
---
README.md | 20 ++++----------------
logos/icon.png | Bin 79760 -> 0 bytes
logos/icon.svg | 18 ------------------
logos/logo-without-text.png | Bin 28986 -> 0 bytes
logos/logo-without-txt.svg | 30 ------------------------------
logos/logo.png | Bin 35006 -> 0 bytes
6 files changed, 4 insertions(+), 64 deletions(-)
delete mode 100644 logos/icon.png
delete mode 100644 logos/icon.svg
delete mode 100644 logos/logo-without-text.png
delete mode 100644 logos/logo-without-txt.svg
delete mode 100644 logos/logo.png
diff --git a/README.md b/README.md
index 09252206..494c349b 100644
--- a/README.md
+++ b/README.md
@@ -14,21 +14,11 @@ 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.
--->
-
-
#
-### Scalable Data Access Policy Management and Enforcement
-
-## Status
-
-This is not the main Palisade Repository, this is the Repository for Palisade Common. For more information, please visit Palisade
-
-
-## Documentation
-
-The documentation for the latest release can be found [here](https://gchq.github.io/Palisade).
+## A Tool for Complex and Scalable Data Access Policy Enforcement
+# Palisade Common
### Prerequisites
1. [Git](https://git-scm.com/)
@@ -134,14 +124,11 @@ cd Palisade-common