add logging

This commit is contained in:
Efstratios Giannopoulos 2024-05-10 12:52:51 +03:00
parent 8b4f9aa75c
commit 89526ebca7
43 changed files with 594 additions and 98 deletions

View File

@ -26,5 +26,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>gr.cite</groupId>
<artifactId>logging</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>
<artifactId>exceptions</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,15 @@
package org.opencdmp.filetransformer.rda.audit;
import gr.cite.tools.logging.EventId;
public class AuditableAction {
public static final EventId FileTransformer_ExportDmp = new EventId(1000, "FileTransformer_ExportDmp");
public static final EventId FileTransformer_ExportDescription = new EventId(1001, "FileTransformer_ExportDescription");
public static final EventId FileTransformer_ImportFileToDmp = new EventId(1002, "FileTransformer_ImportFileToDmp");
public static final EventId FileTransformer_ImportFileToDescription = new EventId(1003, "FileTransformer_ImportFileToDescription");
public static final EventId FileTransformer_GetSupportedFormats = new EventId(1004, "FileTransformer_GetSupportedFormats");
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.util.HashMap;
@ -139,7 +140,7 @@ public class ContactId implements Serializable
public static Type fromValue(String value) {
Type constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.util.HashMap;
@ -140,7 +141,7 @@ public class ContributorId implements Serializable
public static Type fromValue(String value) {
Type constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.util.HashMap;
@ -359,7 +360,7 @@ public class Cost implements Serializable
public static CurrencyCode fromValue(String value) {
CurrencyCode constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.util.HashMap;
@ -568,7 +569,7 @@ public class Dataset implements Serializable
public static PersonalData fromValue(String value) {
PersonalData constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}
@ -608,7 +609,7 @@ public class Dataset implements Serializable
public static SensitiveData fromValue(String value) {
SensitiveData constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.util.HashMap;
@ -149,7 +150,7 @@ public class DatasetId implements Serializable
public static Type fromValue(String value) {
Type constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.net.URI;
@ -399,7 +400,7 @@ public class Distribution implements Serializable
public static DataAccess fromValue(String value) {
DataAccess constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.net.URI;
@ -540,7 +541,7 @@ public class Dmp implements Serializable
public static EthicalIssuesExist fromValue(String value) {
EthicalIssuesExist constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.util.HashMap;
@ -141,7 +142,7 @@ public class DmpId implements Serializable
public static Type fromValue(String value) {
Type constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.util.HashMap;
@ -139,7 +140,7 @@ public class FunderId implements Serializable
public static Type fromValue(String value) {
Type constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.util.HashMap;
@ -172,7 +173,7 @@ public class Funding implements Serializable
public static FundingStatus fromValue(String value) {
FundingStatus constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.util.HashMap;
@ -138,7 +139,7 @@ public class GrantId implements Serializable
public static Type fromValue(String value) {
Type constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.net.URI;
@ -435,7 +436,7 @@ public class Host implements Serializable
public static CertifiedWith fromValue(String value) {
CertifiedWith constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}
@ -721,7 +722,7 @@ public class Host implements Serializable
public static GeoLocation fromValue(String value) {
GeoLocation constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}
@ -761,7 +762,7 @@ public class Host implements Serializable
public static SupportVersioning fromValue(String value) {
SupportVersioning constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@ package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import gr.cite.tools.exception.MyApplicationException;
import java.util.HashMap;
import java.util.Map;
@ -220,7 +221,7 @@ public enum Language {
public static Language fromValue(String value) {
Language constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -2,6 +2,7 @@
package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.*;
import gr.cite.tools.exception.MyApplicationException;
import java.io.Serializable;
import java.util.HashMap;
@ -138,7 +139,7 @@ public class MetadataStandardId implements Serializable
public static Type fromValue(String value) {
Type constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -353,7 +353,7 @@ public class Metadatum implements Serializable
Language constant = CONSTANTS.get(value);
if (constant == null) {
return null;
// throw new IllegalArgumentException(value);
// throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -3,6 +3,7 @@ package org.opencdmp.filetransformer.rda.model.rda;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import gr.cite.tools.exception.MyApplicationException;
import java.util.HashMap;
import java.util.Map;
@ -55,7 +56,7 @@ public enum PidSystem {
public static PidSystem fromValue(String value) {
PidSystem constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
throw new MyApplicationException(value);
} else {
return constant;
}

View File

@ -1,5 +1,6 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import org.opencdmp.commonmodels.enums.ContactInfoType;
import org.opencdmp.commonmodels.models.UserContactInfoModel;
import org.opencdmp.commonmodels.models.UserModel;
@ -20,9 +21,9 @@ public class ContactRDAMapper{
public Contact toRDA(UserModel model) {
if (model == null) return null;
if (model.getName() == null) throw new IllegalArgumentException("Contact Name is missing");
if (model.getName() == null) throw new MyApplicationException("Contact Name is missing");
UserContactInfoModel emailContact = model.getContacts() != null ? model.getContacts().stream().filter(userContactInfo -> userContactInfo.getType().equals(ContactInfoType.Email)).findFirst().orElse(null) : null;
if (emailContact == null) throw new IllegalArgumentException("Contact Email is missing");
if (emailContact == null) throw new MyApplicationException("Contact Email is missing");
Contact rda = new Contact();
rda.setName(model.getName());

View File

@ -1,8 +1,9 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel;
import org.opencdmp.filetransformer.rda.model.rda.Cost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@ -13,11 +14,11 @@ import java.util.stream.Collectors;
@Component
public class CostRDAMapper{
private static final Logger logger = LoggerFactory.getLogger(DatasetRDAMapper.class);
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(CostRDAMapper.class));
public List<Cost> toRDA(Map<String, List<FieldModel>> nodes, List<org.opencdmp.commonmodels.models.description.FieldModel> valueFields ) {
if (nodes == null) return null;
if (valueFields == null) throw new IllegalArgumentException("valueFields is missing");
if (valueFields == null) throw new MyApplicationException("valueFields is missing");
Map<String, Cost> rdaMap = new HashMap<>();
for(Map.Entry<String, List<FieldModel>> entry: nodes.entrySet()){
@ -45,6 +46,7 @@ public class CostRDAMapper{
try {
rda.setValue(Double.valueOf(rdaValue.getTextValue()));
} catch (NumberFormatException e) {
logger.error(e.getMessage(), e);
logger.warn("Dmp cost value " + rdaValue + " is not valid. Cost value will not be set.");
}
} else if (rdaProperty.contains("currency_code")) {
@ -54,6 +56,7 @@ public class CostRDAMapper{
// rda.setCurrencyCode(Cost.CurrencyCode.fromValue(result.get("value")));
rda.setCurrencyCode(Cost.CurrencyCode.fromValue(rdaValue.getTextValue())); //TODO
} catch (Exception e) {
logger.error(e.getMessage(), e);
logger.warn("Dmp cost currency code is not valid and will not be set.");
}
} else if (rdaProperty.contains("title")) {

View File

@ -1,8 +1,9 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel;
import org.opencdmp.filetransformer.rda.model.rda.DatasetId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@ -11,12 +12,11 @@ import java.util.Map;
@Component
public class DatasetIdRDAMapper{
private static final Logger logger = LoggerFactory.getLogger(DatasetIdRDAMapper.class);
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DatasetIdRDAMapper.class));
public DatasetId toRDA(Map<String, List<FieldModel>> nodes, List<org.opencdmp.commonmodels.models.description.FieldModel> valueFields) {
if (nodes == null) return null;
if (valueFields == null) throw new IllegalArgumentException("valueFields is missing");
if (valueFields == null) throw new MyApplicationException("valueFields is missing");
DatasetId data = new DatasetId();
for (Map.Entry<String, List<FieldModel>> entry: nodes.entrySet()) {
@ -63,7 +63,8 @@ public class DatasetIdRDAMapper{
try {
rda.setType(DatasetId.Type.fromValue(value));
}
catch (IllegalArgumentException e){
catch (IllegalArgumentException | MyApplicationException e){
logger.error(e.getMessage(), e);
logger.warn("Type " + value + " from semantic rda.dataset.dataset_id.type was not found. Setting type to OTHER.");
rda.setType(DatasetId.Type.OTHER);
}

View File

@ -1,5 +1,7 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.description.PropertyDefinitionFieldSetItemModel;
import org.opencdmp.commonmodels.models.description.PropertyDefinitionFieldSetModel;
@ -11,7 +13,6 @@ import org.opencdmp.filetransformer.rda.model.rda.DatasetId;
import org.opencdmp.filetransformer.rda.model.rda.Dmp;
import org.opencdmp.filetransformer.rda.model.rda.Language;
import org.opencdmp.filetransformer.rda.service.descriptiontemplatesearcher.TemplateFieldSearcherService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -22,8 +23,8 @@ import java.util.stream.Collectors;
@Component
public class DatasetRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(DatasetRDAMapper.class);
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DatasetRDAMapper.class));
private final TemplateFieldSearcherService templateFieldSearcherService;
private final LanguageRDAMapper languageRDAMapper;
@ -77,10 +78,10 @@ public class DatasetRDAMapper {
public Dataset toRDA(DescriptionModel descriptionEntity, Map<String, Object> extraData) {
if (descriptionEntity == null) return null;
if (descriptionEntity.getLabel() == null) throw new IllegalArgumentException("Dataset Label is missing");
if (extraData == null) throw new IllegalArgumentException("extraData is missing");
if (descriptionEntity.getLabel() == null) throw new MyApplicationException("Dataset Label is missing");
if (extraData == null) throw new MyApplicationException("extraData is missing");
Object dmpObject = extraData.getOrDefault("dmp", null);
if (dmpObject == null) throw new IllegalArgumentException("Dmp is missing");
if (dmpObject == null) throw new MyApplicationException("Dmp is missing");
Dmp dmp = (Dmp)dmpObject;
Dataset rda = new Dataset();
@ -118,7 +119,8 @@ public class DatasetRDAMapper {
List<org.opencdmp.commonmodels.models.description.FieldModel> fieldValues = this.findValueField(languageNode, descriptionEntity.getProperties());
try {
if (!fieldValues.isEmpty()) rda.setLanguage(fieldValues.stream().filter(x -> x.getTextValue() != null && x.getTextValue().isBlank()).map(x -> Language.fromValue(x.getTextValue())).findFirst().orElse(null));
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | MyApplicationException e) {
logger.error(e.getMessage(), e);
logger.warn("Language from semantic rda.dataset.language was not found.");
}
if (rda.getLanguage() != null) break;
@ -307,7 +309,8 @@ public class DatasetRDAMapper {
|| (exists == Dmp.EthicalIssuesExist.UNKNOWN && rdaValue.equals("no"))) {
dmp.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(rdaValue));
}
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | MyApplicationException e) {
logger.error(e.getMessage(), e);
logger.warn(e.getLocalizedMessage() + ". Setting ethical_issues_exist to unknown");
dmp.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN);
}
@ -320,7 +323,8 @@ public class DatasetRDAMapper {
} else if (rdaProperty.contains("report")) {
try {
dmp.setEthicalIssuesReport(URI.create(rdaValue));
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | MyApplicationException e) {
logger.error(e.getMessage(), e);
logger.warn(e.getLocalizedMessage() + ". Skipping url parsing");
}
}
@ -353,6 +357,6 @@ public class DatasetRDAMapper {
public DescriptionModel toEntity(Dataset rda, DescriptionTemplateModel defaultProfile) {
throw new UnsupportedOperationException();
throw new MyApplicationException("Not Supported");
}
}

View File

@ -1,9 +1,10 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel;
import org.opencdmp.filetransformer.rda.model.rda.Distribution;
import org.opencdmp.filetransformer.rda.model.rda.License;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@ -13,7 +14,7 @@ import java.util.stream.Collectors;
@Component
public class DistributionRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(DistributionRDAMapper.class);
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DistributionRDAMapper.class));
private final LicenseRDAMapper licenseRDAMapper;
private final HostRDAMapper hostRDAMapper;
@ -24,7 +25,7 @@ public class DistributionRDAMapper {
public List<Distribution> toRDA(Map<String, List<FieldModel>> nodes, List<org.opencdmp.commonmodels.models.description.FieldModel> valueFields) {
if (nodes == null) return null;
if (valueFields == null) throw new IllegalArgumentException("valueFields is missing");
if (valueFields == null) throw new MyApplicationException("valueFields is missing");
Map<String, Distribution> rdaMap = new HashMap<>();
for (Map.Entry<String, List<FieldModel>> entry: nodes.entrySet()) {
@ -76,7 +77,8 @@ public class DistributionRDAMapper {
try {
rda.setDataAccess(Distribution.DataAccess.fromValue(rdaValue.getTextValue()));
rda.setAdditionalProperty(ImportPropertyName.DATA_ACCESS.getName(), node.getId());
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | MyApplicationException e) {
logger.error(e.getMessage(), e);
logger.warn("Distribution data access " + rdaValue + " from semantic distribution.data_access is not valid. Data access will not be set set.");
}
break;
@ -203,7 +205,7 @@ public class DistributionRDAMapper {
return importPropertyName;
}
}
throw new Exception("No name available");
throw new MyApplicationException("No name available");
}
}
}

View File

@ -1,5 +1,6 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import org.opencdmp.commonmodels.models.dmp.DmpContactModel;
import org.opencdmp.filetransformer.rda.model.rda.Contact;
import org.springframework.stereotype.Component;
@ -20,8 +21,8 @@ public class DmpContactModelContactRDAMapper {
if (model.getUser() != null){
rda = this.contactRDAMapper.toRDA(model.getUser());
} else {
if (model.getLastName() == null) throw new IllegalArgumentException("Last Name is missing");
if (model.getEmail() == null) throw new IllegalArgumentException("Email is missing");
if (model.getLastName() == null) throw new MyApplicationException("Last Name is missing");
if (model.getEmail() == null) throw new MyApplicationException("Email is missing");
rda.setName(model.getLastName() + " " + model.getFirstName());

View File

@ -1,5 +1,6 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import org.opencdmp.commonmodels.enums.DmpAccessType;
import org.opencdmp.commonmodels.enums.DmpUserRole;
import org.opencdmp.commonmodels.models.DmpUserModel;
@ -53,12 +54,12 @@ public class DmpRDAMapper{
}
public Dmp toRDA(DmpModel dmp) {
if (dmp == null) throw new IllegalArgumentException("DMP is missing");
if (dmp.getCreatedAt() == null) throw new IllegalArgumentException("DMP Created is missing");
if (dmp.getUpdatedAt() == null) throw new IllegalArgumentException("DMP Modified is missing");
if (dmp.getLabel() == null) throw new IllegalArgumentException("DMP Label is missing");
if (dmp.getProperties() == null) throw new IllegalArgumentException("DMP is missing language and contact properties");
if (dmp.getDescriptions() == null || dmp.getDescriptions().isEmpty()) throw new IllegalArgumentException("DMP has no Datasets");
if (dmp == null) throw new MyApplicationException("DMP is missing");
if (dmp.getCreatedAt() == null) throw new MyApplicationException("DMP Created is missing");
if (dmp.getUpdatedAt() == null) throw new MyApplicationException("DMP Modified is missing");
if (dmp.getLabel() == null) throw new MyApplicationException("DMP Label is missing");
if (dmp.getProperties() == null) throw new MyApplicationException("DMP is missing language and contact properties");
if (dmp.getDescriptions() == null || dmp.getDescriptions().isEmpty()) throw new MyApplicationException("DMP has no Datasets");
List<ReferenceModel> grants = this.getReferenceModelOfTypeCode(dmp, this.rdaFileTransformerServiceProperties.getGrantReferenceCode());
List<ReferenceModel> researchers = this.getReferenceModelOfTypeCode(dmp, this.rdaFileTransformerServiceProperties.getResearcherReferenceCode());
@ -159,9 +160,9 @@ public class DmpRDAMapper{
}
public DmpModel toEntity(Dmp rda, Map<String, Object> extraData) {
if (extraData == null) throw new IllegalArgumentException("profiles is missing");
if (extraData == null) throw new MyApplicationException("profiles is missing");
Object dmpObject = extraData.getOrDefault("profiles", null);
if (dmpObject == null) throw new IllegalArgumentException("profiles is missing");
if (dmpObject == null) throw new MyApplicationException("profiles is missing");
List<DescriptionTemplateModel> profiles = (List<DescriptionTemplateModel>)dmpObject;
DmpModel entity = new DmpModel();

View File

@ -1,5 +1,6 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import org.opencdmp.commonmodels.enums.ContactInfoType;
import org.opencdmp.commonmodels.models.DmpUserModel;
import org.opencdmp.commonmodels.models.UserContactInfoModel;
@ -22,8 +23,8 @@ public class DmpUserContributorRDAMapper {
public Contributor toRDA(DmpUserModel userDMP) {
if (userDMP == null) return null;
if (userDMP.getUser() == null) throw new IllegalArgumentException("User is missing");
if (userDMP.getUser().getName() == null) throw new IllegalArgumentException("Contributor Name is missing");
if (userDMP.getUser() == null) throw new MyApplicationException("User is missing");
if (userDMP.getUser().getName() == null) throw new MyApplicationException("Contributor Name is missing");
Contributor rda = new Contributor();
rda.setContributorId(contributorIdRDAMapper.toRDA(userDMP.getUser().getId().toString()));

View File

@ -1,9 +1,10 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel;
import org.opencdmp.filetransformer.rda.model.rda.Host;
import org.opencdmp.filetransformer.rda.utils.string.MyStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@ -12,11 +13,11 @@ import java.util.*;
@Component
public class HostRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(HostRDAMapper.class);
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(HostRDAMapper.class));
public Host toRDA(Map<String, List<FieldModel>> nodes, List<org.opencdmp.commonmodels.models.description.FieldModel> valueFields, String numbering){
if (nodes == null) return null;
if (valueFields == null) throw new IllegalArgumentException("valueFields is missing");
if (valueFields == null) throw new MyApplicationException("valueFields is missing");
Host rda = new Host();
for (Map.Entry<String, List<FieldModel>> entry: nodes.entrySet()) {
@ -48,7 +49,8 @@ public class HostRDAMapper {
try {
rda.setCertifiedWith(Host.CertifiedWith.fromValue(rdaValue.getTextValue()));
rda.setAdditionalProperty(ImportPropertyName.CERTIFIED_WITH.getName(), node.getId());
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | MyApplicationException e) {
logger.error(e.getMessage(), e);
logger.warn("Distribution host certified with " + rdaValue + "from semantic distribution.host.certified_with is not valid. Certified_with will not be set set.");
}
break;
@ -68,7 +70,7 @@ public class HostRDAMapper {
// rda.setGeoLocation(Host.GeoLocation.fromValue(rdaValue.getTextValue()));
// rda.setAdditionalProperty(ImportPropertyName.GEO_LOCATION.getName(), node.getId());
// }
// catch (IllegalArgumentException e) {
// catch (IllegalArgumentException | MyApplicationException e) {
// logger.warn("Distribution host geo location " + rdaValue.getTextValue() + "from semantic distribution.host.geo_location is not valid. Geo location will not be set set.");
// }
//TODO
@ -94,7 +96,7 @@ public class HostRDAMapper {
// rda.setPidSystem(pidList);
// rda.setAdditionalProperty(ImportPropertyName.PID_SYSTEM.getName(), node.getId());
// }
// catch (IllegalArgumentException e){
// catch (IllegalArgumentException | MyApplicationException e){
// rda.setPidSystem(new ArrayList<>());
// break;
// } catch (JsonProcessingException e) {
@ -110,7 +112,8 @@ public class HostRDAMapper {
try {
rda.setSupportVersioning(Host.SupportVersioning.fromValue(rdaValue.getTextValue()));
rda.setAdditionalProperty(ImportPropertyName.SUPPORT_VERSIONING.getName(), node.getId());
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | MyApplicationException e) {
logger.error(e.getMessage(), e);
logger.warn("Distribution host support versioning " + rdaValue + "from semantic distribution.host.support_versioning is not valid. Support versioning will not be set set.");
}
break;
@ -122,7 +125,8 @@ public class HostRDAMapper {
try {
rda.setUrl(URI.create(rdaValue.getTextValue()));
rda.setAdditionalProperty(ImportPropertyName.URL.getName(), node.getId());
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | MyApplicationException e) {
logger.error(e.getMessage(), e);
logger.warn(e.getLocalizedMessage() + ". Skipping url parsing");
}
break;
@ -188,13 +192,13 @@ public class HostRDAMapper {
return name;
}
public static ImportPropertyName fromString(String name) throws Exception {
public static ImportPropertyName fromString(String name) {
for (ImportPropertyName importPropertyName: ImportPropertyName.values()) {
if (importPropertyName.getName().equals(name)) {
return importPropertyName;
}
}
throw new Exception("No name available");
throw new MyApplicationException("No name available");
}
}
}

View File

@ -1,10 +1,8 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opencdmp.filetransformer.rda.model.FundingModel;
import org.opencdmp.filetransformer.rda.model.rda.Funding;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.filetransformer.rda.model.rda.Language;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@ -16,8 +14,8 @@ import java.util.*;
@Component
public class LanguageRDAMapper {
private final static Map<String, String> langMap = new HashMap<>();
private static final Logger logger = LoggerFactory.getLogger(LanguageRDAMapper.class);
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(LanguageRDAMapper.class));
static {
try {
ObjectMapper mapper = new ObjectMapper(); //TODO

View File

@ -1,23 +1,23 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel;
import org.opencdmp.filetransformer.rda.model.rda.License;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.net.URI;
import java.util.List;
import java.util.Map;
@Component
public class LicenseRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(LicenseRDAMapper.class);
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(LicenseRDAMapper.class));
public License toRDA(List<FieldModel> nodes, List<org.opencdmp.commonmodels.models.description.FieldModel> valueFields) {
if (nodes == null) return null;
if (valueFields == null) throw new IllegalArgumentException("extraData is missing");
if (valueFields == null) throw new MyApplicationException("extraData is missing");
License rda = new License();
for (FieldModel node: nodes) {
@ -32,7 +32,8 @@ public class LicenseRDAMapper {
case LICENSE_REF:
try {
rda.setLicenseRef(URI.create(valueField.getTextValue()));
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | MyApplicationException e) {
logger.error(e.getMessage(), e);
logger.warn(e.getLocalizedMessage() + ". Skipping url parsing");
}
break;

View File

@ -1,12 +1,13 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel;
import org.opencdmp.commonmodels.models.reference.ReferenceFieldModel;
import org.opencdmp.commonmodels.models.reference.ReferenceModel;
import org.opencdmp.filetransformer.rda.model.rda.Metadatum;
import org.opencdmp.filetransformer.rda.utils.string.MyStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@ -14,8 +15,8 @@ import java.util.*;
@Component
public class MetadataRDAMapper{
private static final Logger logger = LoggerFactory.getLogger(MetadataRDAMapper.class);
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MetadataRDAMapper.class));
private final MetadataStandardIdRDAMapper metadataStandardIdRDAMapper;
public MetadataRDAMapper(MetadataStandardIdRDAMapper metadataStandardIdRDAMapper) {
@ -24,7 +25,7 @@ public class MetadataRDAMapper{
public List<Metadatum> toRDA(Map<String, List<FieldModel>> nodes, List<org.opencdmp.commonmodels.models.description.FieldModel> valueFields) {
if (nodes == null) return null;
if (valueFields == null) throw new IllegalArgumentException("valueFields is missing");
if (valueFields == null) throw new MyApplicationException("valueFields is missing");
Map<String, String> rdaMap = new HashMap<>();
List<Metadatum> rdas = new ArrayList<>();

View File

@ -1,14 +1,14 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.commonmodels.models.reference.ReferenceDefinitionModel;
import org.opencdmp.commonmodels.models.reference.ReferenceFieldModel;
import org.opencdmp.commonmodels.models.reference.ReferenceModel;
import org.opencdmp.commonmodels.models.reference.ReferenceTypeModel;
import org.opencdmp.filetransformer.rda.model.FundingModel;
import org.opencdmp.filetransformer.rda.model.ProjectModel;
import org.opencdmp.filetransformer.rda.model.rda.Funding;
import org.opencdmp.filetransformer.rda.model.rda.Project;
import org.opencdmp.filetransformer.rda.service.rdafiletransformer.RdaFileTransformerServiceProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@ -16,7 +16,7 @@ import java.util.*;
@Component
public class ProjectRDAMapper {
private final static Logger logger = LoggerFactory.getLogger(ProjectRDAMapper.class);
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ProjectRDAMapper.class));
private final FundingRDAMapper fundingRDAMapper;
private final RdaFileTransformerServiceProperties rdaFileTransformerServiceProperties;
@ -27,8 +27,8 @@ public class ProjectRDAMapper {
public Project toRDA(ProjectModel model, Map<String, Object> extraData) {
if (model == null) return null;
if (model.getProject() == null) throw new IllegalArgumentException("Project is missing");
if (model.getProject().getLabel() == null || model.getProject().getLabel().isBlank()) throw new IllegalArgumentException("Project Title is missing");
if (model.getProject() == null) throw new MyApplicationException("Project is missing");
if (model.getProject().getLabel() == null || model.getProject().getLabel().isBlank()) throw new MyApplicationException("Project Title is missing");
Project rda = new Project();
try {
rda.setTitle(model.getProject().getLabel());
@ -50,6 +50,7 @@ public class ProjectRDAMapper {
} catch (Exception e) {
logger.error(e.getMessage(), e);
logger.error(e.getLocalizedMessage(), e);
}

View File

@ -1,5 +1,6 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel;
import org.opencdmp.filetransformer.rda.model.rda.SecurityAndPrivacy;
import org.opencdmp.filetransformer.rda.utils.string.MyStringUtils;
@ -12,7 +13,7 @@ import java.util.stream.Collectors;
public class SecurityAndPrivacyRDAMapper {
public List<SecurityAndPrivacy> toRDA(Map<String, List<FieldModel>> nodes, List<org.opencdmp.commonmodels.models.description.FieldModel> valueFields) {
if (nodes == null) return null;
if (valueFields == null) throw new IllegalArgumentException("valueFields is missing");
if (valueFields == null) throw new MyApplicationException("valueFields is missing");
Map<String, SecurityAndPrivacy> rdaMap = new HashMap<>();
@ -86,13 +87,13 @@ public class SecurityAndPrivacyRDAMapper {
return name;
}
public static ImportPropertyName fromString(String name) throws Exception {
public static ImportPropertyName fromString(String name) {
for (ImportPropertyName importPropertyName: ImportPropertyName.values()) {
if (importPropertyName.getName().equals(name)) {
return importPropertyName;
}
}
throw new Exception("Property not available");
throw new MyApplicationException("Property not available");
}
}
}

View File

@ -1,5 +1,6 @@
package org.opencdmp.filetransformer.rda.model.rda.mapper;
import gr.cite.tools.exception.MyApplicationException;
import org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel;
import org.opencdmp.filetransformer.rda.model.rda.TechnicalResource;
import org.opencdmp.filetransformer.rda.utils.string.MyStringUtils;
@ -13,7 +14,7 @@ public class TechnicalResourceRDAMapper {
public List<TechnicalResource> toRDA(Map<String, List<FieldModel>> nodes, List<org.opencdmp.commonmodels.models.description.FieldModel> valueFields ) {
if (nodes == null) return null;
if (valueFields == null) throw new IllegalArgumentException("valueFields is missing");
if (valueFields == null) throw new MyApplicationException("valueFields is missing");
Map<String, TechnicalResource> rdaMap = new HashMap<>();
for (Map.Entry<String, List<FieldModel>> entry: nodes.entrySet()) {
@ -85,13 +86,13 @@ public class TechnicalResourceRDAMapper {
return name;
}
public static ImportPropertyName fromString(String name) throws Exception {
public static ImportPropertyName fromString(String name) {
for (ImportPropertyName importPropertyName: ImportPropertyName.values()) {
if (importPropertyName.getName().equals(name)) {
return importPropertyName;
}
}
throw new Exception("Property name not available");
throw new MyApplicationException("Property name not available");
}
}
}

View File

@ -47,7 +47,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
this.jsonHandlingService = jsonHandlingService;
}
@Override
public FileEnvelopeModel exportDmp(DmpModel dmpFileTransformerModel, String variant) throws IOException {
public FileEnvelopeModel exportDmp(DmpModel dmpFileTransformerModel, String variant) {
Dmp dmp = this.dmpRDAMapper.toRDA(dmpFileTransformerModel);
RDAModel rdaModel = new RDAModel();
rdaModel.setDmp(dmp);
@ -66,7 +66,7 @@ public class RdaFileTransformerService implements FileTransformerClient {
}
@Override
public FileEnvelopeModel exportDescription(DescriptionModel descriptionFileTransformerModel, String format) throws InvalidApplicationException, IOException {
public FileEnvelopeModel exportDescription(DescriptionModel descriptionFileTransformerModel, String format) {
Dmp dmp = this.dmpRDAMapper.toRDA(descriptionFileTransformerModel.getDmp());
Map<String, Object> datasetExtraData = new HashMap<>();
datasetExtraData.put("dmp", dmp);

View File

@ -1,6 +1,6 @@
package org.opencdmp.filetransformer.rda.service.storage;
import org.slf4j.Logger;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -11,8 +11,8 @@ import java.util.UUID;
@Service
public class FileStorageServiceImpl implements FileStorageService {
private final static Logger logger = LoggerFactory.getLogger(FileStorageServiceImpl.class);
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(FileStorageServiceImpl.class));
private final FileStorageServiceProperties properties;
@Autowired

View File

@ -18,6 +18,8 @@
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.release>21</maven.compiler.release>
<log4j.version>1.2.17</log4j.version>
<log4j2.version>2.15.0</log4j2.version>
<revision>1.0.0-SNAPSHOT</revision>
</properties>
@ -32,6 +34,11 @@
<artifactId>file-transformer-base</artifactId>
<version>0.0.18</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>
<artifactId>logging</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
<modules>

View File

@ -44,6 +44,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>gr.cite</groupId>
<artifactId>exceptions</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
<build>

View File

@ -1,43 +1,90 @@
package org.opencdmp.filetransformer.rda.controller;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.filetransformer.rda.audit.AuditableAction;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerClient;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerConfiguration;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/file-transformer")
public class FileTransformerController implements org.opencdmp.filetransformerbase.interfaces.FileTransformerController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(FileTransformerController.class));
private final FileTransformerClient fileTransformerExecutor;
private final AuditService auditService;
@Autowired
public FileTransformerController(FileTransformerClient fileTransformerExecutor) {
public FileTransformerController(FileTransformerClient fileTransformerExecutor, AuditService auditService) {
this.fileTransformerExecutor = fileTransformerExecutor;
this.auditService = auditService;
}
public FileEnvelopeModel exportDmp(@RequestBody DmpModel dmpDepositModel, @RequestParam(value = "format",required = false)String format) throws Exception {
return fileTransformerExecutor.exportDmp(dmpDepositModel, format);
logger.debug(new MapLogEntry("exportDmp " + DmpModel.class.getSimpleName()).And("dmpDepositModel", dmpDepositModel).And("format", format));
FileEnvelopeModel model = fileTransformerExecutor.exportDmp(dmpDepositModel, format);
this.auditService.track(AuditableAction.FileTransformer_ExportDmp, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("dmpDepositModel", dmpDepositModel),
new AbstractMap.SimpleEntry<String, Object>("format", format)
));
return model;
}
public FileEnvelopeModel exportDescription(@RequestBody DescriptionModel descriptionModel, @RequestParam(value = "format",required = false)String format) throws Exception {
return fileTransformerExecutor.exportDescription(descriptionModel, format);
logger.debug(new MapLogEntry("exportDescription " + DescriptionModel.class.getSimpleName()).And("descriptionModel", descriptionModel).And("format", format));
FileEnvelopeModel model = fileTransformerExecutor.exportDescription(descriptionModel, format);
this.auditService.track(AuditableAction.FileTransformer_ExportDescription, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("descriptionModel", descriptionModel),
new AbstractMap.SimpleEntry<String, Object>("format", format)
));
return model;
}
public DmpModel importFileToDmp(@RequestBody FileEnvelopeModel fileEnvelope) {
return fileTransformerExecutor.importDmp(fileEnvelope);
logger.debug(new MapLogEntry("importFileToDmp " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", fileEnvelope));
DmpModel model = fileTransformerExecutor.importDmp(fileEnvelope);
this.auditService.track(AuditableAction.FileTransformer_ImportFileToDmp, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("fileEnvelope", fileEnvelope)
));
return model;
}
public DescriptionModel importFileToDescription(@RequestBody FileEnvelopeModel fileEnvelope) {
return fileTransformerExecutor.importDescription(fileEnvelope);
logger.debug(new MapLogEntry("importFileToDescription " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", fileEnvelope));
DescriptionModel model = fileTransformerExecutor.importDescription(fileEnvelope);
this.auditService.track(AuditableAction.FileTransformer_ImportFileToDescription, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("importFileToDescription ", fileEnvelope)
));
return model;
}
public FileTransformerConfiguration getSupportedFormats() {
return fileTransformerExecutor.getConfiguration();
logger.debug(new MapLogEntry("getSupportedFormats"));
FileTransformerConfiguration model = fileTransformerExecutor.getConfiguration();
this.auditService.track(AuditableAction.FileTransformer_GetSupportedFormats);
return model;
}
}

View File

@ -0,0 +1,202 @@
package org.opencdmp.filetransformer.rda.controller.controllerhandler;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import gr.cite.tools.exception.*;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
@RestControllerAdvice
@ControllerAdvice
public class GlobalExceptionHandler {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(GlobalExceptionHandler.class));
private final ObjectMapper objectMapper;
public GlobalExceptionHandler() {
this.objectMapper = new ObjectMapper();
this.objectMapper.registerModule(new JavaTimeModule());
}
@ExceptionHandler(Exception.class)
public ResponseEntity<?> handleUnexpectedErrors(Exception exception, WebRequest request) throws Exception {
HandledException handled = this.handleException(exception, request);
this.log(handled.getLevel(), exception, MessageFormat.format("returning code {0} and payload {1}", handled.getStatusCode(), handled.getMessage()));
return new ResponseEntity<>(handled.getMessage(), handled.getStatusCode());
}
public String toJsonSafe(Object item) {
if (item == null) return null;
try {
return this.objectMapper.writeValueAsString(item);
} catch (Exception ex) {
return null;
}
}
public void log(System.Logger.Level level, Exception e, String message) {
if (level != null) {
switch (level) {
case TRACE:
logger.trace(message, e);
break;
case DEBUG:
logger.debug(message, e);
break;
case INFO:
logger.info(message, e);
break;
case WARNING:
logger.warn(message, e);
break;
case ERROR:
logger.error(message, e);
break;
default:
logger.error(e);
}
} else {
logger.error(e);
}
}
public HandledException handleException(Exception exception, WebRequest request) throws Exception {
HttpStatus statusCode;
Map<String, Object> result;
System.Logger.Level logLevel;
switch (exception){
case MyNotFoundException myNotFoundException -> {
logLevel = System.Logger.Level.DEBUG;
statusCode = HttpStatus.NOT_FOUND;
int code = myNotFoundException.getCode();
if (code > 0) {
result = Map.ofEntries(
Map.entry("code", code),
Map.entry("error", myNotFoundException.getMessage())
);
}
else {
result = Map.ofEntries(
Map.entry("error", myNotFoundException.getMessage())
);
}
}
case MyUnauthorizedException myUnauthorizedException -> {
logLevel = System.Logger.Level.DEBUG;
statusCode = HttpStatus.UNAUTHORIZED;
int code = myUnauthorizedException.getCode();
if (code > 0) {
result = Map.ofEntries(
Map.entry("code", code),
Map.entry("error", myUnauthorizedException.getMessage())
);
}
else {
result = Map.ofEntries(
Map.entry("error", myUnauthorizedException.getMessage())
);
}
}
case MyForbiddenException myForbiddenException -> {
logLevel = System.Logger.Level.DEBUG;
statusCode = HttpStatus.FORBIDDEN;
int code = myForbiddenException.getCode();
if (code > 0) {
result = Map.ofEntries(
Map.entry("code", code),
Map.entry("error", myForbiddenException.getMessage())
);
}
else {
result = Map.ofEntries(
Map.entry("error", myForbiddenException.getMessage())
);
}
}
case MyValidationException myValidationException -> {
logLevel = System.Logger.Level.DEBUG;
statusCode = HttpStatus.BAD_REQUEST;
int code = myValidationException.getCode();
result = new HashMap<>();
if (code > 0) result.put("code", code);
if (myValidationException.getMessage() != null) result.put("error", myValidationException.getMessage());
if (myValidationException.getErrors() != null) result.put("message", myValidationException.getErrors());
}
case MyApplicationException myApplicationException -> {
logLevel = System.Logger.Level.ERROR;
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
int code = myApplicationException.getCode();
if (code > 0) {
result = Map.ofEntries(
Map.entry("code", code),
Map.entry("error", myApplicationException.getMessage())
);
}
else {
result = Map.ofEntries(
Map.entry("error", myApplicationException.getMessage())
);
}
}
default -> {
logLevel = System.Logger.Level.ERROR;
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
result = Map.ofEntries(
Map.entry("error", "System error")
);
}
};
String serialization = this.toJsonSafe(result);
return new HandledException(statusCode, serialization, logLevel);
}
public static class HandledException{
public HttpStatus statusCode;
public String message;
public System.Logger.Level level;
public HandledException(HttpStatus statusCode, String message, System.Logger.Level level) {
this.statusCode = statusCode;
this.message = message;
this.level = level;
}
public HttpStatus getStatusCode() {
return statusCode;
}
public void setStatusCode(HttpStatus statusCode) {
this.statusCode = statusCode;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public System.Logger.Level getLevel() {
return level;
}
public void setLevel(System.Logger.Level level) {
this.level = level;
}
}
}

View File

@ -0,0 +1,41 @@
idpclient:
claims:
mapping:
Subject:
- type: sub
Name:
- type: name
Client:
- type: client_id
AuthenticationMethod:
- type: amr
NotBefore:
- type: nbf
AuthenticatedAt:
- type: auth_time
ExpiresAt:
- type: exp
Email:
- type: email
Roles:
- type: resource_access
path: dmp_zenodo_bridge.roles
Scope:
- type: scope
AccessToken:
- type: x-access-token
visibility: SENSITIVE
IssuedAt:
- type: iat
Issuer:
- type: iss
Audience:
- type: aud
TokenType:
- type: typ
AuthorizedParty:
- type: azp
Authorities:
- type: authorities
ExternalProviderName:
- type: identity_provider

View File

@ -0,0 +1,36 @@
logging:
config: classpath:logging/logback-${spring.profiles.active}.xml
context:
request:
requestIdKey: req.id
requestRemoteHostKey: req.remoteHost
requestUriKey: req.requestURI
requestQueryStringKey: req.queryString
requestUrlKey : req.requestURL
requestMethodKey: req.method
requestUserAgentKey: req.userAgent
requestForwardedForKey: req.xForwardedFor
requestSchemeKey: req.scheme
requestRemoteAddressKey: req.remoteAddr
requestRemotePortKey: req.remotePort
requestRemoteUserKey: req.remoteUser
principal:
subjectKey: usr.subject
nameKey: usr.name
clientKey: usr.client
audit:
enable: true
requestRemoteHostKey: req.remoteHost
requestUriKey: req.requestURI
requestQueryStringKey: req.queryString
requestUrlKey : req.requestURL
requestMethodKey: req.method
requestUserAgentKey: req.userAgent
requestForwardedForKey: req.xForwardedFor
requestSchemeKey: req.scheme
requestRemoteAddressKey: req.remoteAddr
requestRemotePortKey: req.remotePort
requestRemoteUserKey: req.remoteUser
principalSubjectKey: usr.subject
principalNameKey: usr.name
principalClientKey: usr.client

View File

@ -0,0 +1,35 @@
logging:
context:
request:
requestIdKey: req.id
requestRemoteHostKey: req.remoteHost
requestUriKey: req.requestURI
requestQueryStringKey: req.queryString
requestUrlKey : req.requestURL
requestMethodKey: req.method
requestUserAgentKey: req.userAgent
requestForwardedForKey: req.xForwardedFor
requestSchemeKey: req.scheme
requestRemoteAddressKey: req.remoteAddr
requestRemotePortKey: req.remotePort
requestRemoteUserKey: req.remoteUser
principal:
subjectKey: usr.subject
nameKey: usr.name
clientKey: usr.client
audit:
enable: true
requestRemoteHostKey: req.remoteHost
requestUriKey: req.requestURI
requestQueryStringKey: req.queryString
requestUrlKey : req.requestURL
requestMethodKey: req.method
requestUserAgentKey: req.userAgent
requestForwardedForKey: req.xForwardedFor
requestSchemeKey: req.scheme
requestRemoteAddressKey: req.remoteAddr
requestRemotePortKey: req.remotePort
requestRemoteUserKey: req.remoteUser
principalSubjectKey: usr.subject
principalNameKey: usr.name
principalClientKey: usr.client

View File

@ -0,0 +1,62 @@
<configuration debug="true">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%date{ISO8601} [%thread] %-5level %logger{36} [%X{req.id}] - %message%n</Pattern>
</encoder>
</appender>
<appender name="TROUBLESHOOTING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/logging.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/logging.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>15</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%date{ISO8601} [%thread] %-5level %logger{36} [%X{req.id}] - %message%n</Pattern>
</encoder>
</appender>
<appender name="AUDITING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/auditing.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/auditing.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>15</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%date{ISO8601} - %X{req.id} - %message%n</Pattern>
</encoder>
</appender>
<logger name="org.springframework.web" level="INFO" additivity="false">
<appender-ref ref="TROUBLESHOOTING"/>
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.hibernate" level="INFO" additivity="false">
<appender-ref ref="TROUBLESHOOTING"/>
<appender-ref ref="STDOUT"/>
</logger>
<logger name="gr.cite" level="DEBUG" additivity="false">
<appender-ref ref="TROUBLESHOOTING"/>
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.opencdmp" level="DEBUG" additivity="false">
<appender-ref ref="TROUBLESHOOTING"/>
<appender-ref ref="STDOUT"/>
</logger>
<logger name="audit" level="INFO" additivity="false">
<appender-ref ref="AUDITING"/>
<appender-ref ref="STDOUT"/>
</logger>
<root level="info">
<appender-ref ref="TROUBLESHOOTING"/>
<appender-ref ref="STDOUT"/>
</root>
</configuration>