Commit fcd9c2e8 authored by neelesh thakur's avatar neelesh thakur
Browse files

merge notification service and legal service updates from opendes

parent 79ddd363
Pipeline #3208 failed with stages
in 6 seconds
......@@ -110,7 +110,7 @@ Below are integration tests showing usage of the entitlement client wrapper
assertFalse( groups.getGroups().stream().anyMatch( (i) -> i.getEmail() == newGroupEmail.getGroupEmail()));
You can configure the environment and credentials used on Entitlements requests using the config. By default it is configured to work in the P4D environment.
You can configure the environment and credentials used on Entitlements requests using the config. By default, it is configured to work in the Opendes environment.
EntitlementsFactory sutFactory = new EntitlementsFactory(
EntitlementsAPIConfig
......
......@@ -6,7 +6,7 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.0.18</version>
<version>0.0.20</version>
<packaging>jar</packaging>
<properties>
......
......@@ -21,7 +21,7 @@ import lombok.Data;
@Data
public class CrsConverterAPIConfig {
@Builder.Default
String rootUrl = "https://crs-converter-dot-p4d-ddl-eu-services.appspot.com/api/crs/v1";
String rootUrl = "https://os-crs-converter-gae-dot-opendes.appspot.com/api/crs/v1";
String apiKey;
......
......@@ -21,7 +21,7 @@ import lombok.Data;
@Data
public class EntitlementsAPIConfig {
@Builder.Default
String rootUrl = "https://entitlements-dot-p4d-ddl-eu-services.appspot.com/entitlements/v1";
String rootUrl = "https://entitlements-dot-opendes.appspot.com/entitlements/v1";
String apiKey;
......
......@@ -21,7 +21,7 @@ import lombok.Data;
@Data
public class LegalAPIConfig {
@Builder.Default
String rootUrl = "https://legal-dot-p4d-ddl-eu-services.appspot.com/api/legal/v1";
String rootUrl = "https://os-legal-dot-opendes.appspot.com/api/legal/v1";
String apiKey;
......
package org.opengroup.osdu.core.common.model.legal;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.Strings;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.opengroup.osdu.core.common.model.legal.serialization.ExpirationDateDeserializer;
import org.opengroup.osdu.core.common.model.legal.validation.ValidDataType;
import org.opengroup.osdu.core.common.model.legal.validation.ValidExportClassification;
import org.opengroup.osdu.core.common.model.legal.validation.ValidLegalTagProperties;
import org.opengroup.osdu.core.common.model.legal.validation.ValidOriginator;
import org.opengroup.osdu.core.common.model.legal.validation.ValidPersonalData;
import org.opengroup.osdu.core.common.model.legal.validation.ValidSecurityClassification;
import lombok.*;
import java.sql.Date;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
......@@ -38,6 +42,8 @@ public class Properties {
private String contractId;
@JsonDeserialize(using = ExpirationDateDeserializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date expirationDate;
@Getter(AccessLevel.NONE)
......@@ -57,11 +63,11 @@ public class Properties {
private String exportClassification;
public Properties(){
public Properties() {
countryOfOrigin = new ArrayList<>();
dataType = "";
securityClassification = "";
personalData= "";
personalData = "";
exportClassification = "";
originator = "";
contractId = "";
......@@ -71,7 +77,8 @@ public class Properties {
public void setCountryOfOrigin(List<String> countryOfOrigin) {
this.countryOfOrigin = countryOfOrigin == null ? null : countryOfOrigin.stream().map(name -> name.toUpperCase()).collect(Collectors.toList()); //expect iso country code so we will enforce uppercase
}
public String getOriginator(){
public String getOriginator() {
return originator == null ? "" : originator;
}
......@@ -80,32 +87,37 @@ public class Properties {
}
@JsonIgnore
public boolean hasExpired(){
public boolean hasExpired() {
return expirationDate.before(new Date(System.currentTimeMillis()));
}
@JsonIgnore
public boolean isDefaultExpirationDate(){
public boolean isDefaultExpirationDate() {
return expirationDate.equals(DEFAULT_EXPIRATIONDATE);
}
@JsonIgnore
public boolean hasThirdPartyDataType(){
public boolean hasThirdPartyDataType() {
return dataType.equalsIgnoreCase(DataTypeValues.THIRD_PARTY_DATA);
}
@JsonIgnore
public boolean hasSecondPartyDataType(){
public boolean hasSecondPartyDataType() {
return dataType.equalsIgnoreCase(DataTypeValues.SECOND_PARTY_DATA);
}
@JsonIgnore
public boolean hasContractId(){
if(Strings.isNullOrEmpty(contractId))
public boolean hasContractId() {
if (Strings.isNullOrEmpty(contractId))
return false;
else if(isUnknownOrNonExistantContractId())
else if (isUnknownOrNonExistantContractId())
return false;
else { //validate it has a properties id
Pattern p = Pattern.compile("^[-.A-Za-z0-9]{3,40}+$");
return p.matcher(contractId).matches();
}
}
@JsonIgnore
public boolean isUnknownOrNonExistantContractId() {
return !Strings.isNullOrEmpty(contractId) && (contractId.equalsIgnoreCase(UNKNOWN_CONTRACT_ID) ||
......
package org.opengroup.osdu.core.common.model.legal.serialization;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.sql.Date;
import java.time.LocalDate;
import org.opengroup.osdu.core.common.model.legal.Properties;
public class ExpirationDateDeserializer extends StdDeserializer<Date> {
public ExpirationDateDeserializer() {
super(Date.class);
}
@Override
public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
final JsonNode expirationDate = jsonParser.getCodec().readTree(jsonParser);
if (expirationDate == null || StringUtils.isBlank(expirationDate.asText())) {
return Properties.DEFAULT_EXPIRATIONDATE;
}
return Date.valueOf(LocalDate.parse(expirationDate.asText()));
}
}
\ No newline at end of file
package org.opengroup.osdu.core.common.model.notification;
class Constants {
public static final String GSAString = "GSA";
public static final String HMACString = "HMAC";
}
\ No newline at end of file
package org.opengroup.osdu.core.common.model.notification;
import lombok.Data;
@Data
public class GsaSecret extends Secret {
private GsaSecretValue value;
public GsaSecret() {
super(Constants.GSAString);
}
}
\ No newline at end of file
package org.opengroup.osdu.core.common.model.notification;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GsaSecretValue {
private String audience;
private String key;
}
\ No newline at end of file
package org.opengroup.osdu.core.common.model.notification;
import lombok.Data;
@Data
public class HmacSecret extends Secret {
private String value;
public HmacSecret() {
super(Constants.HMACString);
}
}
\ No newline at end of file
package org.opengroup.osdu.core.common.model.notification;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "secretType")
@JsonSubTypes({
@JsonSubTypes.Type(value = HmacSecret.class, name = Constants.HMACString),
@JsonSubTypes.Type(value = GsaSecret.class, name = Constants.GSAString)}
)
public abstract class Secret {
private String secretType;
protected Secret(String secretType) {
this.secretType = secretType;
}
}
\ No newline at end of file
package org.opengroup.osdu.core.common.model.notification;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Subscription {
private String name = "";
private String description = "";
private String topic = "";
private String pushEndpoint = "";
private String notificationId = "";
private String id = "";
private String createdBy = "";
private Secret secret;
}
\ No newline at end of file
package org.opengroup.osdu.core.common.model.notification;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class SubscriptionInfo {
private String name = "";
private String description = "";
private String topic = "";
private String pushEndpoint = "";
private String notificationId = "";
private String id = "";
private String createdBy = "";
public SubscriptionInfo(Subscription subscription) {
this.name = subscription.getName();
this.description = subscription.getDescription();
this.topic = subscription.getTopic();
this.pushEndpoint = subscription.getPushEndpoint();
this.notificationId = subscription.getNotificationId();
this.id = subscription.getId();
this.createdBy = subscription.getCreatedBy();
}
}
package org.opengroup.osdu.core.common.model.notification;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class Topic {
private String name;
private String description;
private String state;
private Object example;
}
package org.opengroup.osdu.core.common.notification;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
public interface ISubscriptionFactory {
ISubscriptionService create(DpsHeaders headers);
}
\ No newline at end of file
package org.opengroup.osdu.core.common.notification;
import org.opengroup.osdu.core.common.model.notification.Subscription;
import org.opengroup.osdu.core.common.model.notification.SubscriptionInfo;
import org.opengroup.osdu.core.common.model.notification.Topic;
import java.util.List;
public interface ISubscriptionService {
Subscription create(Subscription lt) throws SubscriptionException;
SubscriptionInfo get(String subscriptionId) throws SubscriptionException;
void delete(String subscriptionId) throws SubscriptionException;
List<Topic> getTopics() throws SubscriptionException;
List<Subscription> query(String notificationId) throws SubscriptionException;
}
\ No newline at end of file
package org.opengroup.osdu.core.common.notification;
import lombok.Builder;
import lombok.Data;
@Builder
@Data
public class SubscriptionAPIConfig {
@Builder.Default
String rootUrl = "https://os-register-dot-opendes.appspot.com/api/register/v1";
String apiKey;
public static SubscriptionAPIConfig Default() {
return SubscriptionAPIConfig.builder().build();
}
}
package org.opengroup.osdu.core.common.notification;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.opengroup.osdu.core.common.http.HttpResponse;
import org.opengroup.osdu.core.common.model.http.DpsException;
@Data
@EqualsAndHashCode(callSuper = false)
public class SubscriptionException extends DpsException {
private static final long serialVersionUID = -3557182069722613408L;
public SubscriptionException(String message, HttpResponse httpResponse) {
super(message, httpResponse);
}
public SubscriptionException(String message, HttpResponse httpResponse, Exception ex) {
super(message, httpResponse);
this.initCause(ex);
}
}
package org.opengroup.osdu.core.common.notification;
import org.opengroup.osdu.core.common.http.HttpClient;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
public class SubscriptionFactory implements ISubscriptionFactory {
public SubscriptionFactory(SubscriptionAPIConfig config) {
if (config == null) {
throw new IllegalArgumentException("SubscriptionAPIConfig cannot be empty");
}
this.config = config;
}
private final SubscriptionAPIConfig config;
@Override
public ISubscriptionService create(DpsHeaders headers) {
if (headers == null) {
throw new NullPointerException("headers cannot be null");
}
return new SubscriptionService(this.config, new HttpClient(), headers);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment