Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Diamantis Tziotzios 2023-11-23 09:48:21 +02:00
commit c779bd00f0
48 changed files with 2995 additions and 27 deletions

View File

@ -74,6 +74,11 @@ public class AuditableAction {
public static final EventId User_LookupByEmail = new EventId(11004, "User_LookupByEmail");
public static final EventId User_ExportCsv = new EventId(11005, "User_ExportCsv");
public static final EventId User_PersistRoles = new EventId(11004, "User_PersistRoles");
public static final EventId Tenant_Query = new EventId(12000, "Tenant_Query");
public static final EventId Tenant_Lookup = new EventId(12001, "Tenant_Lookup");
public static final EventId Tenant_Persist = new EventId(12002, "Tenant_Persist");
public static final EventId Tenant_Delete = new EventId(12003, "Tenant_Delete");
}

View File

@ -139,5 +139,10 @@ public final class Permission {
public static String EditReferenceType= "EditReferenceType";
public static String DeleteReferenceType = "DeleteReferenceType";
//Tenant
public static String BrowseTenant = "BrowseTenant";
public static String EditTenant= "EditTenant";
public static String DeleteTenant = "DeleteTenant";
}

View File

@ -0,0 +1,112 @@
package eu.eudat.data;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.enums.IsActiveConverter;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.UUID;
@Entity
@Table(name = "\"Tenant\"")
public class TenantEntity {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public final static String _id = "id";
@Column(name = "code", length = 200, nullable = false)
private String code;
public final static String _code = "code";
@Column(name = "name", length = 500, nullable = false)
private String name;
public final static String _name = "name";
@Column(name = "description", nullable = false)
private String description;
public final static String _description = "description";
@Column(name = "is_active", length = 20, nullable = false)
@Convert(converter = IsActiveConverter.class)
private IsActive isActive;
public final static String _isActive = "isActive";
@Column(name = "config")
private String config;
public final static String _config = "config";
@Column(name = "created_at", nullable = false)
private Instant createdAt;
public final static String _createdAt = "createdAt";
@Column(name = "updated_at", nullable = false)
private Instant updatedAt;
public final static String _updatedAt = "updatedAt";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
}

View File

@ -0,0 +1,108 @@
package eu.eudat.model;
import eu.eudat.commons.enums.IsActive;
import java.time.Instant;
import java.util.UUID;
public class Tenant {
private UUID id;
public final static String _id = "id";
private String code;
public final static String _code = "code";
private String name;
public final static String _name = "name";
private String description;
public final static String _description = "description";
private IsActive isActive;
public final static String _isActive = "isActive";
private String config;
public final static String _config = "config";
private Instant createdAt;
public final static String _createdAt = "createdAt";
private Instant updatedAt;
public final static String _updatedAt = "updatedAt";
public final static String _hash = "hash";
private String hash;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
}

View File

@ -0,0 +1,56 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.TenantEntity;
import eu.eudat.model.Tenant;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantBuilder extends BaseBuilder<Tenant, TenantEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public TenantBuilder(ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantBuilder.class)));
}
public TenantBuilder authorize(EnumSet<AuthorizationFlags> values){
this.authorize = values;
return this;
}
@Override
public List<Tenant> build(FieldSet fields, List<TenantEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0),Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size) .orElse(0));
this.logger.trace(new DataLogEntry("requested fields",fields));
if(fields == null || data == null || fields.isEmpty()) return new ArrayList<>();
List<Tenant> models = new ArrayList<>();
for(TenantEntity d : data){
Tenant m = new Tenant();
if(fields.hasField(this.asIndexer(Tenant._id))) m.setId(d.getId());
if(fields.hasField(this.asIndexer(Tenant._code))) m.setCode(d.getCode());
if(fields.hasField(this.asIndexer(Tenant._name))) m.setName(d.getName());
if(fields.hasField(this.asIndexer(Tenant._description))) m.setDescription(d.getDescription());
if(fields.hasField(this.asIndexer(Tenant._isActive))) m.setIsActive(d.getIsActive());
if(fields.hasField(this.asIndexer(Tenant._config))) m.setConfig(d.getConfig());
if(fields.hasField(this.asIndexer(Tenant._createdAt))) m.setCreatedAt(d.getCreatedAt());
if(fields.hasField(this.asIndexer(Tenant._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if(fields.hasField(this.asIndexer(Tenant._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
models.add(m);
}
this.logger.debug("build {} items",Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -0,0 +1,42 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public TenantCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseTenant);
}
}

View File

@ -0,0 +1,79 @@
package eu.eudat.model.deleter;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.TenantEntity;
import eu.eudat.query.TenantQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
protected final DeleterFactory deleterFactory;
@Autowired
public TenantDeleter(
EntityManager entityManager,
QueryFactory queryFactory,
DeleterFactory deleterFactory
) {
this.entityManager = entityManager;
this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<TenantEntity> data = this.queryFactory.query(TenantQuery.class).ids(ids).collect();
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<TenantEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<TenantEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
Instant now = Instant.now();
for (TenantEntity item : data) {
logger.trace("deleting item {}", item.getId());
item.setIsActive(IsActive.Inactive);
item.setUpdatedAt(now);
logger.trace("updating item");
this.entityManager.merge(item);
logger.trace("updated item");
}
}
}

View File

@ -0,0 +1,80 @@
package eu.eudat.model.persist;
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
import eu.eudat.commons.validation.ValidId;
import jakarta.validation.constraints.*;
import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class TenantPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max= 200, message = "{validation.largerthanmax}")
private String code;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max= 500, message = "{validation.largerthanmax}")
private String name;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String description;
private String config;
private String hash;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
}

View File

@ -0,0 +1,161 @@
package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.TenantEntity;
import eu.eudat.model.Tenant;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantQuery extends QueryBase<TenantEntity> {
private String like;
private Collection<UUID> ids;
private Collection<IsActive> isActives;
private Collection<UUID> excludedIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public TenantQuery like(String value) {
this.like = value;
return this;
}
public TenantQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public TenantQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public TenantQuery ids(Collection<UUID> values) {
this.ids = values;
return this;
}
public TenantQuery isActive(IsActive value) {
this.isActives = List.of(value);
return this;
}
public TenantQuery isActive(IsActive... value) {
this.isActives = Arrays.asList(value);
return this;
}
public TenantQuery isActive(Collection<IsActive> values) {
this.isActives = values;
return this;
}
public TenantQuery excludedIds(Collection<UUID> values) {
this.excludedIds = values;
return this;
}
public TenantQuery excludedIds(UUID value) {
this.excludedIds = List.of(value);
return this;
}
public TenantQuery excludedIds(UUID... value) {
this.excludedIds = Arrays.asList(value);
return this;
}
public TenantQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.isActives);
}
@Override
protected Class<TenantEntity> entityClass() {
return TenantEntity.class;
}
@Override
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>();
if (this.ids != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantEntity._id));
for (UUID item : this.ids) inClause.value(item);
predicates.add(inClause);
}
if (this.like != null && !this.like.isEmpty()) {
predicates.add(queryContext.CriteriaBuilder.or(queryContext.CriteriaBuilder.like(queryContext.Root.get(TenantEntity._code), this.like),
queryContext.CriteriaBuilder.like(queryContext.Root.get(TenantEntity._name), this.like)
));
}
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantEntity._isActive));
for (IsActive item : this.isActives) inClause.value(item);
predicates.add(inClause);
}
if (this.excludedIds != null) {
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantEntity._id));
for (UUID item : this.excludedIds)
notInClause.value(item);
predicates.add(notInClause.not());
}
if (predicates.size() > 0) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray);
} else {
return null;
}
}
@Override
protected TenantEntity convert(Tuple tuple, Set<String> columns) {
TenantEntity item = new TenantEntity();
item.setId(QueryBase.convertSafe(tuple, columns, TenantEntity._id, UUID.class));
item.setCode(QueryBase.convertSafe(tuple, columns, TenantEntity._code, String.class));
item.setName(QueryBase.convertSafe(tuple, columns, TenantEntity._name, String.class));
item.setDescription(QueryBase.convertSafe(tuple, columns, TenantEntity._description, String.class));
item.setConfig(QueryBase.convertSafe(tuple, columns, TenantEntity._config, String.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, TenantEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, TenantEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, TenantEntity._isActive, IsActive.class));
return item;
}
@Override
protected String fieldNameOf(FieldResolver item) {
if (item.match(Tenant._id)) return TenantEntity._id;
else if (item.match(Tenant._code)) return TenantEntity._code;
else if (item.match(Tenant._name)) return TenantEntity._name;
else if (item.match(Tenant._description)) return TenantEntity._description;
else if (item.match(Tenant._config)) return TenantEntity._config;
else if (item.match(Tenant._createdAt)) return TenantEntity._createdAt;
else if (item.match(Tenant._updatedAt)) return TenantEntity._updatedAt;
else if (item.match(Tenant._isActive)) return TenantEntity._isActive;
else return null;
}
}

View File

@ -0,0 +1,61 @@
package eu.eudat.query.lookup;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.query.TenantQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import java.util.List;
import java.util.UUID;
public class TenantLookup extends Lookup {
private String like;
private List<IsActive> isActive;
private List<UUID> ids;
private List<UUID> excludedIds;
public String getLike() {
return like;
}
public void setLike(String like) {
this.like = like;
}
public List<IsActive> getIsActive() {
return isActive;
}
public void setIsActive(List<IsActive> isActive) {
this.isActive = isActive;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public List<UUID> getExcludedIds() {
return excludedIds;
}
public void setExcludedIds(List<UUID> excludeIds) {
this.excludedIds = excludeIds;
}
public TenantQuery enrich(QueryFactory queryFactory) {
TenantQuery query = queryFactory.query(TenantQuery.class);
if (this.like != null) query.like(this.like);
if (this.isActive != null) query.isActive(this.isActive);
if (this.ids != null) query.ids(this.ids);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
this.enrichCommon(query);
return query;
}
}

View File

@ -0,0 +1,19 @@
package eu.eudat.service.tenant;
import eu.eudat.model.Tenant;
import eu.eudat.model.persist.TenantPersist;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.FieldSet;
import javax.management.InvalidApplicationException;
import java.util.UUID;
public interface TenantService {
Tenant persist(TenantPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
}

View File

@ -0,0 +1,129 @@
package eu.eudat.service.tenant;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.TenantEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.Tenant;
import eu.eudat.model.builder.TenantBuilder;
import eu.eudat.model.deleter.TenantDeleter;
import eu.eudat.model.persist.TenantPersist;
import eu.eudat.service.responseutils.ResponseUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidationService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Service
public class TenantServiceImpl implements TenantService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantServiceImpl.class));
private final EntityManager entityManager;
private final AuthorizationService authorizationService;
private final DeleterFactory deleterFactory;
private final BuilderFactory builderFactory;
private final ConventionService conventionService;
private final MessageSource messageSource;
private final QueryFactory queryFactory;
private final ResponseUtilsService responseUtilsService;
private final XmlHandlingService xmlHandlingService;
private final ErrorThesaurusProperties errors;
private final ValidationService validationService;
@Autowired
public TenantServiceImpl(
EntityManager entityManager,
AuthorizationService authorizationService,
DeleterFactory deleterFactory,
BuilderFactory builderFactory,
ConventionService conventionService,
MessageSource messageSource, QueryFactory queryFactory,
ResponseUtilsService responseUtilsService,
XmlHandlingService xmlHandlingService,
ErrorThesaurusProperties errors,
ValidationService validationService) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
this.builderFactory = builderFactory;
this.conventionService = conventionService;
this.messageSource = messageSource;
this.queryFactory = queryFactory;
this.responseUtilsService = responseUtilsService;
this.xmlHandlingService = xmlHandlingService;
this.errors = errors;
this.validationService = validationService;
}
@Override
public Tenant persist(TenantPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting data").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.EditTenant);
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
TenantEntity data;
if (isUpdate) {
data = this.entityManager.find(TenantEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Tenant.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
} else {
data = new TenantEntity();
data.setId(UUID.randomUUID());
data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now());
}
data.setCode(model.getCode());
data.setName(model.getName());
data.setDescription(model.getDescription());
data.setUpdatedAt(Instant.now());
data.setConfig(model.getConfig());
if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data);
this.entityManager.flush();
return this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Tenant._id), data);
}
@Override
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting : {}", id);
this.authorizationService.authorizeForce(Permission.DeleteTenant);
this.deleterFactory.deleter(TenantDeleter.class).deleteAndSaveByIds(List.of(id));
}
}

View File

@ -0,0 +1,135 @@
package eu.eudat.controllers.v2;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.data.TenantEntity;
import eu.eudat.model.Tenant;
import eu.eudat.model.builder.TenantBuilder;
import eu.eudat.model.censorship.TenantCensor;
import eu.eudat.model.persist.TenantPersist;
import eu.eudat.model.result.QueryResult;
import eu.eudat.query.TenantQuery;
import eu.eudat.query.lookup.TenantLookup;
import eu.eudat.service.tenant.TenantService;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.transaction.Transactional;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.management.InvalidApplicationException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@RestController
@RequestMapping(path = "api/tenant")
public class TenantController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantController.class));
private final BuilderFactory builderFactory;
private final AuditService auditService;
private final TenantService tenantService;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
public TenantController(
BuilderFactory builderFactory,
AuditService auditService,
TenantService tenantService,
CensorFactory censorFactory,
QueryFactory queryFactory,
MessageSource messageSource) {
this.builderFactory = builderFactory;
this.auditService = auditService;
this.tenantService = tenantService;
this.censorFactory = censorFactory;
this.queryFactory = queryFactory;
this.messageSource = messageSource;
}
@PostMapping("query")
public QueryResult<Tenant> query(@RequestBody TenantLookup lookup) throws MyApplicationException, MyForbiddenException {
logger.debug("querying {}", Tenant.class.getSimpleName());
this.censorFactory.censor(TenantCensor.class).censor(lookup.getProject(), null);
TenantQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic);
List<TenantEntity> data = query.collectAs(lookup.getProject());
List<Tenant> models = this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data);
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.Tenant_Query, "lookup", lookup);
return new QueryResult<>(models, count);
}
@GetMapping("{id}")
public Tenant get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + Tenant.class.getSimpleName()).And("id", id).And("fields", fieldSet));
this.censorFactory.censor(TenantCensor.class).censor(fieldSet, null);
TenantQuery query = this.queryFactory.query(TenantQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id);
Tenant model = this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Tenant.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.Tenant_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return model;
}
@PostMapping("persist")
@Transactional
public Tenant persist(@MyValidate @RequestBody TenantPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
logger.debug(new MapLogEntry("persisting" + Tenant.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
this.censorFactory.censor(TenantCensor.class).censor(fieldSet, null);
Tenant persisted = this.tenantService.persist(model, fieldSet);
this.auditService.track(AuditableAction.Tenant_Persist, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return persisted;
}
@DeleteMapping("{id}")
@Transactional
public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug(new MapLogEntry("retrieving" + Tenant.class.getSimpleName()).And("id", id));
this.tenantService.deleteAndSave(id);
this.auditService.track(AuditableAction.Tenant_Delete, "id", id);
}
}

View File

@ -490,6 +490,27 @@ permissions:
allowAnonymous: false
allowAuthenticated: false
# ReferenceType Permissions
BrowseTenant:
roles:
- Admin
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
EditTenant:
roles:
- Admin
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
DeleteTenant:
roles:
- Admin
claims: [ ]
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
# DmpDescriptionTemplate Permissions
BrowseDmpDescriptionTemplate:

View File

@ -252,7 +252,15 @@ const appRoutes: Routes = [
loadChildren: () => import('./ui/admin/reference-type/reference-type.module').then(m => m.ReferenceTypeModule),
data: {
breadcrumb: true,
title: 'GENERAL.TITLES.REFERENCE-TYPE'
title: 'GENERAL.TITLES.REFERENCE-TYPES'
},
},
{
path: 'tenants',
loadChildren: () => import('./ui/admin/tenant/tenant.module').then(m => m.TenantModule),
data: {
breadcrumb: true,
title: 'GENERAL.TITLES.TENANTS'
},
},
{

View File

@ -23,5 +23,10 @@ export enum AppPermission {
BrowseReferenceType = "BrowseReferenceType",
EditReferenceType = "EditReferenceType",
DeleteReferenceType = "DeleteReferenceType",
//Tenant
BrowseTenant = "BrowseTenant",
EditTenant = "EditTenant",
DeleteTenant = "DeleteTenant",
}

View File

@ -59,6 +59,7 @@ import { FileUtils } from './services/utilities/file-utils.service';
import { QueryParamsService } from './services/utilities/query-params.service';
import { DescriptionTemplateService } from './services/description-template/description-template.service';
import { ReferenceTypeService } from './services/reference-type/reference-type.service';
import { TenantService } from './services/tenant/tenant.service';
//
//
// This is shared module that provides all the services. Its imported only once on the AppModule.
@ -136,7 +137,8 @@ export class CoreServiceModule {
FileUtils,
ReferenceService,
DescriptionTemplateService,
ReferenceTypeService
ReferenceTypeService,
TenantService
],
};
}

View File

@ -0,0 +1,17 @@
import { BaseEntity, BaseEntityPersist } from "@common/base/base-entity.model";
export interface Tenant extends BaseEntity{
name: string;
code: string;
description: string;
config: string;
}
//persist
export interface TenantPersist extends BaseEntityPersist{
name: string;
code: string;
description: string;
config: string;
}

View File

@ -0,0 +1,21 @@
import { Lookup } from '@common/model/lookup';
import { Guid } from '@common/types/guid';
import { IsActive } from '../common/enum/is-active.enum';
export class TenantLookup extends Lookup implements TenantFilter {
ids: Guid[];
excludedIds: Guid[];
like: string;
isActive: IsActive[];
constructor() {
super();
}
}
export interface TenantFilter {
ids: Guid[];
excludedIds: Guid[];
like: string;
isActive: IsActive[];
}

View File

@ -0,0 +1,94 @@
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { Tenant, TenantPersist } from '@app/core/model/tenant/tenant';
import { TenantLookup } from '@app/core/query/tenant.lookup';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
import { QueryResult } from '@common/model/query-result';
import { FilterService } from '@common/modules/text-filter/filter-service';
import { Guid } from '@common/types/guid';
import { Observable, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof';
import { ConfigurationService } from '../configuration/configuration.service';
import { BaseHttpV2Service } from '../http/base-http-v2.service';
@Injectable()
export class TenantService {
constructor(private http: BaseHttpV2Service, private configurationService: ConfigurationService, private filterService: FilterService) {
}
private get apiBase(): string { return `${this.configurationService.server}tenant`; }
query(q: TenantLookup): Observable<QueryResult<Tenant>> {
const url = `${this.apiBase}/query`;
return this.http.post<QueryResult<Tenant>>(url, q).pipe(catchError((error: any) => throwError(error)));
}
getSingle(id: Guid, reqFields: string[] = []): Observable<Tenant> {
const url = `${this.apiBase}/${id}`;
const options = { params: { f: reqFields } };
return this.http
.get<Tenant>(url, options).pipe(
catchError((error: any) => throwError(error)));
}
persist(item: TenantPersist): Observable<Tenant> {
const url = `${this.apiBase}/persist`;
return this.http
.post<Tenant>(url, item).pipe(
catchError((error: any) => throwError(error)));
}
delete(id: Guid): Observable<Tenant> {
const url = `${this.apiBase}/${id}`;
return this.http
.delete<Tenant>(url).pipe(
catchError((error: any) => throwError(error)));
}
//
// Autocomplete Commons
//
// tslint:disable-next-line: member-ordering
singleAutocompleteConfiguration: SingleAutoCompleteConfiguration = {
initialItems: (data?: any) => this.query(this.buildAutocompleteLookup()).pipe(map(x => x.items)),
filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup(searchQuery)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup(null, null, [selectedItem])).pipe(map(x => x.items[0])),
displayFn: (item: Tenant) => item.name,
titleFn: (item: Tenant) => item.name,
valueAssign: (item: Tenant) => item.id,
};
// tslint:disable-next-line: member-ordering
multipleAutocompleteConfiguration: MultipleAutoCompleteConfiguration = {
initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup(null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)),
filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup(searchQuery, excludedItems)).pipe(map(x => x.items)),
getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup(null, null, selectedItems)).pipe(map(x => x.items)),
displayFn: (item: Tenant) => item.name,
titleFn: (item: Tenant) => item.name,
valueAssign: (item: Tenant) => item.id,
};
private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): TenantLookup {
const lookup: TenantLookup = new TenantLookup();
lookup.page = { size: 100, offset: 0 };
if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; }
if (ids && ids.length > 0) { lookup.ids = ids; }
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
nameof<Tenant>(x => x.id),
nameof<Tenant>(x => x.name)
]
};
lookup.order = { items: [nameof<Tenant>(x => x.name)] };
if (like) { lookup.like = this.filterService.transformLike(like); }
return lookup;
}
}

View File

@ -80,12 +80,8 @@ export class ReferenceTypeEditorResolver extends BaseEditorResolver {
...ReferenceTypeEditorResolver.lookupFields()
];
const id = route.paramMap.get('id');
//const cloneid = route.paramMap.get('cloneid');
if (id != null) {
return this.ReferenceTypeService.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.code)), takeUntil(this._destroyed));
}
// } else if (cloneid != null) {
// return this.ReferenceTypeService.clone(Guid.parse(cloneid), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.label)), takeUntil(this._destroyed));
// }
}
}

View File

@ -0,0 +1,71 @@
<div class="tenant-editor">
<div class="row align-items-center mb-4" *ngIf="formGroup">
<div class="col-auto">
<h3 *ngIf="isNew && !isClone">{{'TENANT-EDITOR.NEW' | translate}}</h3>
<app-navigation-breadcrumb />
</div>
<div class="col-auto">
<button mat-button class="action-btn" (click)="cancel()" type="button">{{'REFERENCE-TYPE-EDITOR.ACTIONS.CANCEL' | translate}}</button>
</div>
<div class="col-auto" *ngIf="!isNew">
<button mat-button class="action-btn" type="button" (click)="delete()">
<mat-icon>delete</mat-icon>
{{'TENANT-EDITOR.ACTIONS.DELETE' | translate}}
</button>
</div>
<div class="col-auto" *ngIf="canSave">
<button mat-button class="action-btn" (click)="formSubmit()">
<mat-icon>save</mat-icon>
{{'TENANT-EDITOR.ACTIONS.SAVE' | translate}}
</button>
</div>
</div>
<form *ngIf="formGroup" (ngSubmit)="formSubmit()">
<mat-card appearance="outlined">
<mat-card-header>
<mat-card-title *ngIf="isNew">{{'TENANT-EDITOR.NEW' | translate}}</mat-card-title>
</mat-card-header>
<mat-card-content>
<div class="row">
<div class="col-4">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.NAME' | translate}}</mat-label>
<input matInput type="text" name="name" [formControl]="formGroup.get('name')" required>
<mat-error *ngIf="formGroup.get('name').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-4">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" name="code" [formControl]="formGroup.get('code')" required>
<mat-error *ngIf="formGroup.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-12">
<h3>{{'TENANT-EDITOR.FIELDS.DESCRIPTION' | translate}}</h3>
<div class="col-12">
<rich-text-editor-component [parentFormGroup]="formGroup" [controlName]="'description'" [placeholder]="'DATASET-PROFILE-EDITOR.STEPS.GENERAL-INFO.DATASET-TEMPLATE-DESCRIPTION-PLACEHOLDER'" [wrapperClasses]="(formGroup.get('description').touched && formGroup.get('description').hasError('required')) ? 'required' : ''" [editable]="formGroup.controls['description'].status !== 'DISABLED'">
</rich-text-editor-component>
<div [class]="(formGroup.get('description').touched && formGroup.get('description').hasError('required')) ? 'visible' : 'invisible'" class="mat-form-field formGroup-field-subscript-wrapper">
<mat-error>
{{'GENERAL.VALIDATION.REQUIRED'| translate}}
</mat-error>
</div>
</div>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'TENANT-EDITOR.FIELDS.NAME' | translate}}</mat-label>
<input matInput type="text" name="config" [formControl]="formGroup.get('config')" required>
<mat-error *ngIf="formGroup.get('config').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
</mat-card-content>
</mat-card>
</form>
</div>

View File

@ -0,0 +1,116 @@
.tenant-editor {
margin-top: 1.3rem;
margin-left: 1em;
margin-right: 3em;
.remove {
background-color: white;
color: black;
}
.add {
background-color: white;
color: #009700;
}
}
::ng-deep .mat-checkbox-checked.mat-accent .mat-checkbox-background, .mat-checkbox-indeterminate.mat-accent .mat-checkbox-background {
background-color: var(--primary-color-3);
// background-color: #0070c0;
}
::ng-deep .mat-checkbox-disabled.mat-checkbox-checked .mat-checkbox-background, .mat-checkbox-disabled.mat-checkbox-indeterminate .mat-checkbox-background {
background-color: #b0b0b0;
}
.finalize-btn {
border-radius: 30px;
border: 1px solid var(--primary-color);
background: transparent;
padding-left: 2em;
padding-right: 2em;
box-shadow: 0px 3px 6px #1E202029;
color: var(--primary-color);
&:disabled{
background-color: #CBCBCB;
color: #FFF;
border: 0px;
}
}
.action-btn {
border-radius: 30px;
background-color: var(--secondary-color);
border: 1px solid transparent;
padding-left: 2em;
padding-right: 2em;
box-shadow: 0px 3px 6px #1E202029;
transition-property: background-color, color;
transition-duration: 200ms;
transition-delay: 50ms;
transition-timing-function: ease-in-out;
&:disabled{
background-color: #CBCBCB;
color: #FFF;
border: 0px;
}
}
.dlt-section-btn {
margin: 0;
position: absolute;
top: 50%;
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.section-input {
position: relative;
}
.section-input .arrows {
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
}
.action-list-item{
display: flex;
align-items: center;
cursor: pointer;
.action-list-icon{
font-size: 1.2em;
// padding-right: 1em;
// width: 14px;
// margin-right: 0.5em;
// margin-left: -.09em;
// height: auto;
color: var(--primary-color);
}
.action-list-text{
font-size: 1em;
color: var(--primary-color);
}
}
.field-delete{
align-items: center;
display: flex;
cursor: pointer;
.field-delete-icon{
font-size: 1.2em;
width: 14px;
color: var(--primary-color);
}
.field-delete-text{
font-size: 1em;
margin-left: 0.5em;
color: var(--primary-color);
}
}

View File

@ -0,0 +1,185 @@
import { Component, OnInit } from '@angular/core';
import { FormArray, UntypedFormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { TenantService } from '@app/core/services/tenant/tenant.service';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
// import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
import { DatePipe } from '@angular/common';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { AppPermission } from '@app/core/common/enum/permission.enum';
import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile';
import { Tenant, TenantPersist } from '@app/core/model/tenant/tenant';
import { AuthService } from '@app/core/services/auth/auth.service';
import { DmpService } from '@app/core/services/dmp/dmp.service';
import { LoggingService } from '@app/core/services/logging/logging-service';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { FileUtils } from '@app/core/services/utilities/file-utils.service';
import { QueryParamsService } from '@app/core/services/utilities/query-params.service';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { BaseEditor } from '@common/base/base-editor';
import { FormService } from '@common/forms/form-service';
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
import { FilterService } from '@common/modules/text-filter/filter-service';
import { Guid } from '@common/types/guid';
import { TranslateService } from '@ngx-translate/core';
import { map, takeUntil } from 'rxjs/operators';
import { TenantEditorResolver } from './tenant-editor.resolver';
import { TenantEditorService } from './tenant-editor.service';
import { TenantEditorModel } from './tenant-editor.model';
@Component({
selector: 'app-tenant-editor-component',
templateUrl: 'tenant-editor.component.html',
styleUrls: ['./tenant-editor.component.scss'],
providers: [TenantEditorService]
})
export class TenantEditorComponent extends BaseEditor<TenantEditorModel, Tenant> implements OnInit {
isNew = true;
isDeleted = false;
formGroup: UntypedFormGroup = null;
showInactiveDetails = false;
protected get canDelete(): boolean {
return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteTenant);
}
protected get canSave(): boolean {
return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditTenant);
}
protected get canFinalize(): boolean {
return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditTenant);
}
private hasPermission(permission: AppPermission): boolean {
return this.authService.hasPermission(permission) || this.editorModel?.permissions?.includes(permission);
}
constructor(
// BaseFormEditor injected dependencies
protected dialog: MatDialog,
protected language: TranslateService,
protected formService: FormService,
protected router: Router,
protected uiNotificationService: UiNotificationService,
protected httpErrorHandlingService: HttpErrorHandlingService,
protected filterService: FilterService,
protected datePipe: DatePipe,
protected route: ActivatedRoute,
protected queryParamsService: QueryParamsService,
// Rest dependencies. Inject any other needed deps here:
public authService: AuthService,
public enumUtils: EnumUtils,
private tenantService: TenantService,
private logger: LoggingService,
private tenantEditorService: TenantEditorService,
private fileUtils: FileUtils,
private matomoService: MatomoService
) {
super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService);
}
ngOnInit(): void {
this.matomoService.trackPageView('Admin: Tenants');
super.ngOnInit();
}
getItem(itemId: Guid, successFunction: (item: Tenant) => void) {
this.tenantService.getSingle(itemId, TenantEditorResolver.lookupFields())
.pipe(map(data => data as Tenant), takeUntil(this._destroyed))
.subscribe(
data => successFunction(data),
error => this.onCallbackError(error)
);
}
prepareForm(data: Tenant) {
try {
this.editorModel = data ? new TenantEditorModel().fromModel(data) : new TenantEditorModel();
this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
this.buildForm();
} catch (error) {
this.logger.error('Could not parse Tenant item: ' + data + error);
this.uiNotificationService.snackBarNotification(this.language.instant('COMMONS.ERRORS.DEFAULT'), SnackBarNotificationLevel.Error);
}
}
buildForm() {
this.formGroup = this.editorModel.buildForm(null, this.isDeleted || !this.authService.hasPermission(AppPermission.EditTenant));
this.tenantEditorService.setValidationErrorModel(this.editorModel.validationErrorModel);
}
refreshData(): void {
this.getItem(this.editorModel.id, (data: Tenant) => this.prepareForm(data));
}
refreshOnNavigateToData(id?: Guid): void {
this.formGroup.markAsPristine();
let route = [];
if (id === null) {
route.push('../..');
} else if (this.isNew) {
route.push('../' + id);
} else {
route.push('..');
}
this.router.navigate(route, { queryParams: { 'lookup': this.queryParamsService.serializeLookup(this.lookupParams), 'lv': ++this.lv }, replaceUrl: true, relativeTo: this.route });
}
persistEntity(onSuccess?: (response) => void): void {
const formData = this.formService.getValue(this.formGroup.value) as TenantPersist;
this.tenantService.persist(formData)
.pipe(takeUntil(this._destroyed)).subscribe(
complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete),
error => this.onCallbackError(error)
);
}
formSubmit(): void {
this.formService.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) {
return;
}
this.persistEntity();
}
public delete() {
const value = this.formGroup.value;
if (value.id) {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
maxWidth: '300px',
data: {
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
this.tenantService.delete(value.id).pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onCallbackSuccess(),
error => this.onCallbackError(error)
);
}
});
}
}
clearErrorModel() {
this.editorModel.validationErrorModel.clear();
this.formService.validateAllFormFields(this.formGroup);
}
}

View File

@ -0,0 +1,58 @@
import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms";
import { Tenant, TenantPersist } from "@app/core/model/tenant/tenant";
import { BaseEditorModel } from "@common/base/base-form-editor-model";
import { BackendErrorValidator } from "@common/forms/validation/custom-validator";
import { ValidationErrorModel } from "@common/forms/validation/error-model/validation-error-model";
import { Validation, ValidationContext } from "@common/forms/validation/validation-context";
export class TenantEditorModel extends BaseEditorModel implements TenantPersist {
name: string;
code: string;
description: string;
config: string;
permissions: string[];
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor() { super(); }
public fromModel(item: Tenant): TenantEditorModel {
if (item) {
super.fromModel(item);
this.name = item.name;
this.code = item.code;
this.description = item.description;
this.config = item.config;
}
return this;
}
buildForm(context: ValidationContext = null, disabled: boolean = false): UntypedFormGroup {
if (context == null) { context = this.createValidationContext(); }
return this.formBuilder.group({
id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators],
name: [{ value: this.name, disabled: disabled }, context.getValidation('name').validators],
code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators],
description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators],
config: [{ value: this.config, disabled: disabled }, context.getValidation('config').validators],
hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators]
});
}
createValidationContext(): ValidationContext {
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(this.validationErrorModel, 'id')] });
baseValidationArray.push({ key: 'name', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'name')] });
baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'code')] });
baseValidationArray.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'description')] });
baseValidationArray.push({ key: 'config', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'config')] });
baseValidationArray.push({ key: 'hash', validators: [] });
baseContext.validation = baseValidationArray;
return baseContext;
}
}

View File

@ -0,0 +1,44 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Tenant } from '@app/core/model/tenant/tenant';
import { TenantService } from '@app/core/services/tenant/tenant.service';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { BaseEditorResolver } from '@common/base/base-editor.resolver';
import { Guid } from '@common/types/guid';
import { takeUntil, tap } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof';
@Injectable()
export class TenantEditorResolver extends BaseEditorResolver {
constructor(private TenantService: TenantService, private breadcrumbService: BreadcrumbService) {
super();
}
public static lookupFields(): string[] {
return [
...BaseEditorResolver.lookupFields(),
nameof<Tenant>(x => x.id),
nameof<Tenant>(x => x.name),
nameof<Tenant>(x => x.code),
nameof<Tenant>(x => x.description),
nameof<Tenant>(x => x.config),
nameof<Tenant>(x => x.createdAt),
nameof<Tenant>(x => x.updatedAt),
nameof<Tenant>(x => x.hash),
nameof<Tenant>(x => x.isActive)
]
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const fields = [
...TenantEditorResolver.lookupFields()
];
const id = route.paramMap.get('id');
if (id != null) {
return this.TenantService.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.code)), takeUntil(this._destroyed));
}
}
}

View File

@ -0,0 +1,15 @@
import { Injectable } from "@angular/core";
import { ValidationErrorModel } from "@common/forms/validation/error-model/validation-error-model";
@Injectable()
export class TenantEditorService {
private validationErrorModel: ValidationErrorModel;
public setValidationErrorModel(validationErrorModel: ValidationErrorModel): void {
this.validationErrorModel = validationErrorModel;
}
public getValidationErrorModel(): ValidationErrorModel {
return this.validationErrorModel;
}
}

View File

@ -0,0 +1,36 @@
<div class="d-flex align-items-center gap-1-rem">
<button mat-flat-button [matMenuTriggerFor]="filterMenu" #filterMenuTrigger="matMenuTrigger" (click)="updateFilters()" class="filter-button">
<mat-icon aria-hidden="false" [matBadgeHidden]="!appliedFilterCount" [matBadge]="appliedFilterCount" matBadgeColor="warn" matBadgeSize="small">filter_alt</mat-icon>
{{'COMMONS.LISTING-COMPONENT.SEARCH-FILTER-BTN' | translate}}
</button>
<mat-menu #filterMenu>
<div class="p-3" (click)="$event?.stopPropagation?.()">
<div class="search-listing-filters-container">
<div class="d-flex align-items-center justify-content-between">
<h4>{{'TENANT-LISTING.FILTER.TITLE' | translate}}</h4>
<button color="accent" mat-button (click)="clearFilters()">
{{'COMMONS.LISTING-COMPONENT.CLEAR-ALL-FILTERS' | translate}}
</button>
</div>
<mat-slide-toggle labelPosition="before" [(ngModel)]="internalFilters.isActive">
{{'TENANT-LISTING.FILTER.IS-ACTIVE' | translate}}
</mat-slide-toggle>
<div class="d-flex justify-content-end align-items-center mt-4 gap-1-rem">
<button mat-stroked-button color="primary" (click)="filterMenuTrigger?.closeMenu()">
{{'TENANT-LISTING.FILTER.CANCEL' | translate}}
</button>
<button mat-raised-button color="primary" (click)="filterMenuTrigger.closeMenu(); applyFilters();">
{{'TENANT-LISTING.FILTER.APPLY-FILTERS' | translate}}
</button>
</div>
</div>
</div>
</mat-menu>
<app-expandable-search-field [(value)]=internalFilters.like (valueChange)="onSearchTermChange($event)" />
</div>

View File

@ -0,0 +1,25 @@
.description-template-type-listing-filters {
}
::ng-deep.mat-mdc-menu-panel {
max-width: 100% !important;
height: 100% !important;
}
:host::ng-deep.mat-mdc-menu-content:not(:empty) {
padding-top: 0 !important;
}
.filter-button{
padding-top: .6rem;
padding-bottom: .6rem;
// .mat-icon{
// font-size: 1.5em;
// width: 1.2em;
// height: 1.2em;
// }
}

View File

@ -0,0 +1,94 @@
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { TenantFilter } from '@app/core/query/tenant.lookup';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { BaseComponent } from '@common/base/base.component';
import { nameof } from 'ts-simple-nameof';
@Component({
selector: 'app-tenant-listing-filters',
templateUrl: './tenant-listing-filters.component.html',
styleUrls: ['./tenant-listing-filters.component.scss']
})
export class TenantListingFiltersComponent extends BaseComponent implements OnInit, OnChanges {
@Input() readonly filter: TenantFilter;
@Output() filterChange = new EventEmitter<TenantFilter>();
// * State
internalFilters: TenantListingFilters = this._getEmptyFilters();
protected appliedFilterCount: number = 0;
constructor(
public enumUtils: EnumUtils,
) { super(); }
ngOnInit() {
}
ngOnChanges(changes: SimpleChanges): void {
const filterChange = changes[nameof<TenantListingFiltersComponent>(x => x.filter)]?.currentValue as TenantFilter;
if (filterChange) {
this.updateFilters()
}
}
onSearchTermChange(searchTerm: string): void {
this.applyFilters()
}
protected updateFilters(): void {
this.internalFilters = this._parseToInternalFilters(this.filter);
this.appliedFilterCount = this._computeAppliedFilters(this.internalFilters);
}
protected applyFilters(): void {
const { isActive, like } = this.internalFilters ?? {}
this.filterChange.emit({
...this.filter,
like,
isActive: isActive ? [IsActive.Active] : [IsActive.Inactive]
})
}
private _parseToInternalFilters(inputFilter: TenantFilter): TenantListingFilters {
if (!inputFilter) {
return this._getEmptyFilters();
}
let { excludedIds, ids, isActive, like } = inputFilter;
return {
isActive: (isActive ?? [])?.includes(IsActive.Active) || !isActive?.length,
like: like
}
}
private _getEmptyFilters(): TenantListingFilters {
return {
isActive: true,
like: null,
}
}
private _computeAppliedFilters(filters: TenantListingFilters): number {
let count = 0;
if (filters?.isActive) {
count++
}
return count;
}
clearFilters() {
this.internalFilters = this._getEmptyFilters();
}
}
interface TenantListingFilters {
isActive: boolean;
like: string;
}

View File

@ -0,0 +1,108 @@
<div class="row tenant-listing">
<div class="col-md-8 offset-md-2">
<div class="row mb-4 mt-3">
<div class="col">
<h4>{{'TENANT-LISTING.TITLE' | translate}}</h4>
<app-navigation-breadcrumb />
</div>
<div class="col-auto">
<button mat-raised-button class="create-btn"
*ngIf="authService.hasPermission(authService.permissionEnum.EditDescriptionTemplateType)"
[routerLink]="['/tenants/new']">
<mat-icon>add</mat-icon>
{{'TENANT-LISTING.CREATE' | translate}}
</button>
</div>
</div>
<app-hybrid-listing [rows]="gridRows" [columns]="gridColumns" [visibleColumns]="visibleColumns"
[count]="totalElements" [offset]="currentPageNumber" [limit]="lookup.page.size"
[defaultSort]="lookup.order?.items" [externalSorting]="true" (rowActivated)="onRowActivated($event)"
(pageLoad)="alterPage($event)" (columnSort)="onColumnSort($event)"
(columnsChanged)="onColumnsChanged($event)" [listItemTemplate]="listItemTemplate">
<app-tenant-listing-filters hybrid-listing-filters [(filter)]="lookup"
(filterChange)="filterChanged($event)" />
<app-user-settings-picker [key]="userSettingsKey" [userPreference]="lookup"
(onSettingSelected)="changeSetting($event)" [autoSelectUserSettings]="autoSelectUserSettings"
user-preference-settings />
<!-- <button mat-icon-button download-listing-report>
<mat-icon>download</mat-icon>
</button> -->
</app-hybrid-listing>
</div>
</div>
<ng-template #listItemTemplate let-item="item" let-isColumnSelected="isColumnSelected">
<div class="d-flex align-items-center p-3 gap-1-rem">
<div class="row">
<ng-container *ngIf="isColumnSelected('name')">
<a class="buttonLinkClass" [routerLink]="'./' + item?.id" class="col-12"
(click)="$event.stopPropagation()">{{item?.name | nullifyValue}}</a>
<br />
</ng-container>
<ng-container *ngIf="isColumnSelected('status')">
<div class="col-auto">
<div class="status-chip"
[ngClass]="{'status-chip-finalized': item.status === descriptionTemplateTypeStatuses.Finalized, 'status-chip-draft' : item.status === descriptionTemplateTypeStatuses.Draft}">
{{enumUtils.toDescriptionTemplateTypeStatusString(item.status) | nullifyValue}}
</div>
</div>
</ng-container>
<ng-container *ngIf="isColumnSelected('createdAt')">
<span class="col-12">
{{'TENANT-LISTING.FIELDS.CREATED-AT' | translate}}:
<small>
{{item?.createdAt | dateTimeFormatter : 'short' | nullifyValue}}
</small>
</span>
<br>
</ng-container>
<ng-container *ngIf="isColumnSelected('updatedAt')">
<span class="col-12">
{{'TENANT-LISTING.FIELDS.UPDATED-AT' | translate}}:
<small>
{{item?.updatedAt | dateTimeFormatter : 'short' | nullifyValue}}
</small>
</span>
</ng-container>
</div>
</div>
</ng-template>
<!-- <ng-template #tenantStatus let-row="row" let-item>
<div class="row">
<div class="col-auto status-chip"
[ngClass]="{'status-chip-finalized': row.status === descriptionTemplateTypeStatuses.Finalized, 'status-chip-draft' : row.status === descriptionTemplateTypeStatuses.Draft}">
{{enumUtils.toDescriptionTemplateTypeStatusString(row.status) | nullifyValue}}
</div>
</div>
</ng-template> -->
<ng-template #actions let-row="row" let-item>
<div class="row" (click)="$event.stopPropagation()">
<div class="col-auto">
<button mat-icon-button [matMenuTriggerFor]="actionsMenu">
<mat-icon>more_horiz</mat-icon>
</button>
<mat-menu #actionsMenu="matMenu">
<button mat-menu-item [routerLink]="['/tenant/' + row.id]">
<mat-icon>edit</mat-icon>{{'TENANT-LISTING.ACTIONS.EDIT' | translate}}
</button>
<button mat-menu-item (click)="deleteType(row.id)">
<mat-icon>delete</mat-icon>
{{'TENANT-LISTING.ACTIONS.DELETE' | translate}}
</button>
<!--<button *ngIf="row.status==1" mat-menu-item (click)="makeItPublic(row.id)"><mat-icon>people_outline</mat-icon>{{'DATASET-LISTING.ACTIONS.MAKE-IT-PUBLIC' | translate}}</button> -->
</mat-menu>
</div>
</div>
</ng-template>

View File

@ -0,0 +1,60 @@
.description-template-type-listing {
margin-top: 1.3rem;
margin-left: 1rem;
margin-right: 2rem;
.mat-header-row{
background: #f3f5f8;
}
.mat-card {
margin: 16px 0;
padding: 0px;
}
.mat-row {
cursor: pointer;
min-height: 4.5em;
}
mat-row:hover {
background-color: #eef5f6;
}
.mat-fab-bottom-right {
float: right;
z-index: 5;
}
}
.create-btn {
border-radius: 30px;
background-color: var(--secondary-color);
padding-left: 2em;
padding-right: 2em;
// color: #000;
.button-text{
display: inline-block;
}
}
.dlt-btn {
color: rgba(0, 0, 0, 0.54);
}
.status-chip{
border-radius: 20px;
padding-left: 1em;
padding-right: 1em;
padding-top: 0.2em;
font-size: .8em;
}
.status-chip-finalized{
color: #568b5a;
background: #9dd1a1 0% 0% no-repeat padding-box;
}
.status-chip-draft{
color: #00c4ff;
background: #d3f5ff 0% 0% no-repeat padding-box;
}

View File

@ -0,0 +1,170 @@
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { Tenant } from '@app/core/model/tenant/tenant';
import { TenantLookup } from '@app/core/query/tenant.lookup';
import { AuthService } from '@app/core/services/auth/auth.service';
import { TenantService } from '@app/core/services/tenant/tenant.service';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { QueryParamsService } from '@app/core/services/utilities/query-params.service';
import { BaseListingComponent } from '@common/base/base-listing-component';
import { PipeService } from '@common/formatting/pipe.service';
import { DataTableDateTimeFormatPipe } from '@common/formatting/pipes/date-time-format.pipe';
import { QueryResult } from '@common/model/query-result';
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
import { ColumnDefinition, ColumnsChangedEvent, HybridListingComponent, PageLoadEvent } from '@common/modules/hybrid-listing/hybrid-listing.component';
import { Guid } from '@common/types/guid';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof';
@Component({
templateUrl: './tenant-listing.component.html',
styleUrls: ['./tenant-listing.component.scss']
})
export class TenantListingComponent extends BaseListingComponent<Tenant, TenantLookup> implements OnInit {
publish = false;
userSettingsKey = { key: 'TenantListingUserSettings' };
propertiesAvailableForOrder: ColumnDefinition[];
// @ViewChild('TenantStatus', { static: true }) TenantStatus?: TemplateRef<any>;
@ViewChild('actions', { static: true }) actions?: TemplateRef<any>;
@ViewChild(HybridListingComponent, { static: true }) hybridListingComponent: HybridListingComponent;
private readonly lookupFields: string[] = [
nameof<Tenant>(x => x.id),
nameof<Tenant>(x => x.name),
nameof<Tenant>(x => x.code),
nameof<Tenant>(x => x.updatedAt),
nameof<Tenant>(x => x.createdAt),
nameof<Tenant>(x => x.hash),
nameof<Tenant>(x => x.isActive)
];
rowIdentity = x => x.id;
constructor(
protected router: Router,
protected route: ActivatedRoute,
protected uiNotificationService: UiNotificationService,
protected httpErrorHandlingService: HttpErrorHandlingService,
protected queryParamsService: QueryParamsService,
private TenantService: TenantService,
public authService: AuthService,
private pipeService: PipeService,
public enumUtils: EnumUtils,
private language: TranslateService,
private dialog: MatDialog
) {
super(router, route, uiNotificationService, httpErrorHandlingService, queryParamsService);
// Lookup setup
// Default lookup values are defined in the user settings class.
this.lookup = this.initializeLookup();
}
ngOnInit() {
super.ngOnInit();
}
protected initializeLookup(): TenantLookup {
const lookup = new TenantLookup();
lookup.metadata = { countAll: true };
lookup.page = { offset: 0, size: this.ITEMS_PER_PAGE };
lookup.isActive = [IsActive.Active];
lookup.order = { items: [this.toDescSortField(nameof<Tenant>(x => x.createdAt))] };
this.updateOrderUiFields(lookup.order);
lookup.project = {
fields: this.lookupFields
};
return lookup;
}
protected setupColumns() {
this.gridColumns.push(...[{
prop: nameof<Tenant>(x => x.name),
sortable: true,
languageName: 'TENANT-LISTING.FIELDS.NAME'
}, {
prop: nameof<Tenant>(x => x.code),
sortable: true,
languageName: 'TENANT-LISTING.FIELDS.CODE',
//cellTemplate: this.TenantStatus
},
{
prop: nameof<Tenant>(x => x.createdAt),
sortable: true,
languageName: 'TENANT-LISTING.FIELDS.CREATED-AT',
pipe: this.pipeService.getPipe<DataTableDateTimeFormatPipe>(DataTableDateTimeFormatPipe).withFormat('short')
},
{
prop: nameof<Tenant>(x => x.updatedAt),
sortable: true,
languageName: 'TENANT-LISTING.FIELDS.UPDATED-AT',
pipe: this.pipeService.getPipe<DataTableDateTimeFormatPipe>(DataTableDateTimeFormatPipe).withFormat('short')
},
{
alwaysShown: true,
cellTemplate: this.actions,
maxWidth: 120
}
]);
this.propertiesAvailableForOrder = this.gridColumns.filter(x => x.sortable);
}
//
// Listing Component functions
//
onColumnsChanged(event: ColumnsChangedEvent) {
super.onColumnsChanged(event);
this.onColumnsChangedInternal(event.properties.map(x => x.toString()));
}
private onColumnsChangedInternal(columns: string[]) {
// Here are defined the projection fields that always requested from the api.
const fields = new Set(this.lookupFields);
this.gridColumns.map(x => x.prop)
.filter(x => !columns?.includes(x as string))
.forEach(item => {
fields.delete(item as string)
});
this.lookup.project = { fields: [...fields] };
this.onPageLoad({ offset: 0 } as PageLoadEvent);
}
protected loadListing(): Observable<QueryResult<Tenant>> {
return this.TenantService.query(this.lookup);
}
public deleteType(id: Guid) {
if (id) {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
data: {
isDeleteConfirmation: true,
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
this.TenantService.delete(id).pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onCallbackSuccess(),
error => this.onCallbackError(error)
);
}
});
}
}
onCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success);
this.ngOnInit();
}
}

View File

@ -0,0 +1,41 @@
import { DragDropModule } from '@angular/cdk/drag-drop';
import { NgModule } from "@angular/core";
import { AutoCompleteModule } from "@app/library/auto-complete/auto-complete.module";
import { UrlListingModule } from '@app/library/url-listing/url-listing.module';
import { CommonFormattingModule } from '@common/formatting/common-formatting.module';
import { CommonFormsModule } from '@common/forms/common-forms.module';
import { ConfirmationDialogModule } from '@common/modules/confirmation-dialog/confirmation-dialog.module';
import { HybridListingModule } from "@common/modules/hybrid-listing/hybrid-listing.module";
import { TextFilterModule } from "@common/modules/text-filter/text-filter.module";
import { UserSettingsModule } from "@common/modules/user-settings/user-settings.module";
import { CommonUiModule } from '@common/ui/common-ui.module';
import { NgxDropzoneModule } from "ngx-dropzone";
import { TenantRoutingModule } from './tenant.routing';
import { TenantEditorComponent } from './editor/tenant-editor.component';
import { TenantListingComponent } from './listing/tenant-listing.component';
import { TenantListingFiltersComponent } from "./listing/filters/tenant-listing-filters.component";
import { RichTextEditorModule } from '@app/library/rich-text-editor/rich-text-editor.module';
@NgModule({
imports: [
CommonUiModule,
CommonFormsModule,
UrlListingModule,
ConfirmationDialogModule,
TenantRoutingModule,
NgxDropzoneModule,
DragDropModule,
AutoCompleteModule,
HybridListingModule,
TextFilterModule,
UserSettingsModule,
CommonFormattingModule,
RichTextEditorModule
],
declarations: [
TenantEditorComponent,
TenantListingComponent,
TenantListingFiltersComponent
]
})
export class TenantModule { }

View File

@ -0,0 +1,58 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AdminAuthGuard } from '@app/core/admin-auth-guard.service';
import { TenantEditorComponent } from './editor/tenant-editor.component';
import { TenantListingComponent } from './listing/tenant-listing.component';
import { AppPermission } from '@app/core/common/enum/permission.enum';
import { AuthGuard } from '@app/core/auth-guard.service';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { PendingChangesGuard } from '@common/forms/pending-form-changes/pending-form-changes-guard.service';
import { TenantEditorResolver } from './editor/tenant-editor.resolver';
const routes: Routes = [
{
path: '',
component: TenantListingComponent,
canActivate: [AuthGuard]
},
{
path: 'new',
canActivate: [AuthGuard],
component: TenantEditorComponent,
canDeactivate: [PendingChangesGuard],
data: {
authContext: {
permissions: [AppPermission.EditTenant]
},
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.NEW-TENANT'
})
}
},
{
path: ':id',
canActivate: [AuthGuard],
component: TenantEditorComponent,
canDeactivate: [PendingChangesGuard],
resolve: {
'entity': TenantEditorResolver
},
data: {
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.EDIT-TENANT'
}),
authContext: {
permissions: [AppPermission.EditTenant]
}
}
},
{ path: '**', loadChildren: () => import('@common/modules/page-not-found/page-not-found.module').then(m => m.PageNotFoundModule) },
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: [TenantEditorResolver]
})
export class TenantRoutingModule { }

View File

@ -54,6 +54,7 @@ export const ADMIN_ROUTES: RouteInfo[] = [
{ path: '/description-templates', title: 'SIDE-BAR.DESCRIPTION-TEMPLATES', icon: 'library_books' },
{ path: '/description-template-type', title: 'SIDE-BAR.DESCRIPTION-TEMPLATE-TYPES', icon: 'library_books' },
{ path: '/reference-type', title: 'SIDE-BAR.REFERENCE-TYPES', icon: 'library_books' },
{ path: '/tenants', title: 'SIDE-BAR.TENANTS', icon: 'library_books' },
{ path: '/users', title: 'SIDE-BAR.USERS', icon: 'people' },
{ path: '/language-editor', title: 'SIDE-BAR.LANGUAGE-EDITOR', icon: 'language' },
{ path: '/supportive-material', title: 'SIDE-BAR.SUPPORTIVE-MATERIAL', icon: 'import_contacts' }

View File

@ -172,7 +172,8 @@
"GUIDE-EDITOR": "User Guide Editor",
"LANGUAGE": "Language",
"SIGN-IN": "Sign in to account",
"REFERENCE-TYPE": "Reference Types"
"REFERENCE-TYPES": "Reference Types",
"TENANTS": "Tenants"
},
"FILE-TYPES": {
"PDF": "PDF",
@ -241,7 +242,9 @@
"NEW-DESCRIPTION-TEMPLATES": "New",
"EDIT-DESCRIPTION-TEMPLATES": "Edit",
"NEW-REFERENCE-TYPE": "New",
"EDIT-REFERENCE-TYPE": "Edit"
"EDIT-REFERENCE-TYPE": "Edit",
"NEW-TENANT": "New",
"EDIT-TENANT": "Edit"
},
"COOKIE": {
"MESSAGE": "This website uses cookies to enhance the user experience.",
@ -336,7 +339,8 @@
"SUPPORT": "Support",
"FEEDBACK": "Send feedback",
"SUPPORTIVE-MATERIAL": "Supportive Material",
"REFERENCE-TYPES":"Reference Types"
"REFERENCE-TYPES":"Reference Types",
"TENANTS": "Tenants"
},
"DESCRIPTION-TEMPLATE-EDITOR": {
"TITLE": {
@ -1078,6 +1082,33 @@
"SUCCESSFUL-DELETE": "Successful Delete",
"UNSUCCESSFUL-DELETE": "This item could not be deleted."
},
"TENANT-LISTING": {
"TITLE": "Tenants",
"CREATE": "Create Tenant",
"FIELDS": {
"NAME": "Name",
"CODE": "Code",
"UPDATED-AT": "Updated",
"CREATED-AT": "Created"
},
"FILTER": {
"TITLE": "Filters",
"IS-ACTIVE": "Is Active",
"CANCEL": "Cancel",
"APPLY-FILTERS": "Apply filters"
},
"CONFIRM-DELETE-DIALOG": {
"MESSAGE": "Would you like to delete this Tenant?",
"CONFIRM-BUTTON": "Yes, delete",
"CANCEL-BUTTON": "No"
},
"ACTIONS": {
"DELETE": "Delete",
"EDIT": "Edit"
},
"SUCCESSFUL-DELETE": "Successful Delete",
"UNSUCCESSFUL-DELETE": "This item could not be deleted."
},
"DATASET-UPLOAD": {
"TITLE": "Import Dataset",
"UPLOAD-BUTTON": "Upload",
@ -1169,6 +1200,24 @@
"CANCEL-BUTTON": "No"
}
},
"TENANT-EDITOR": {
"NEW": "New Tenant",
"FIELDS": {
"NAME": "Name",
"CODE": "Code",
"DESCRIPTION": "Description"
},
"ACTIONS": {
"SAVE": "Save",
"CANCEL": "Cancel",
"DELETE": "Delete"
},
"CONFIRM-DELETE-DIALOG": {
"MESSAGE": "Would you like to delete this Tenant?",
"CONFIRM-BUTTON": "Yes, delete",
"CANCEL-BUTTON": "No"
}
},
"DMP-BLUEPRINT-EDITOR": {
"TITLE": {
"NEW": "New DMP Blueprint",

View File

@ -0,0 +1,72 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.ReferenceEntity;
import eu.old.eudat.data.dao.entities.DataRepositoryDao;
import eu.old.eudat.data.entities.DataRepository;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
@Service
public class DataRepositoryMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DataRepositoryMigrationService.class));
private static final int PageSize = 500;
private static final String InternalReferenceSource = "dmp";
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
public DataRepositoryMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
public void migrate(){
DataRepositoryDao dataRepositoryDao = databaseRepository.getDataRepositoryDao();
long total = dataRepositoryDao.asQueryable().count();
logger.debug("Migrate DataRepository Total : " + total);
int page = 0;
List<DataRepository> items;
do {
items = dataRepositoryDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate DataRepository " + page * PageSize + " of " + total);
for (DataRepository item : items) {
entityManager.detach(item);
if (item.getReference() == null || !item.getReference().contains(":")){
logger.warn("Reference generated because is null DataRepository " + item.getId());
item.setReference(InternalReferenceSource + ":" + item.getId().toString().toLowerCase(Locale.ROOT));
}
eu.old.eudat.models.data.datarepository.DataRepositoryModel model = new eu.old.eudat.models.data.datarepository.DataRepositoryModel().fromDataModel(item);
String[] referenceParts = item.getReference().split(":", 2);
boolean isInternal = referenceParts[0].equals(InternalReferenceSource);
ReferenceEntity data = new ReferenceEntity();
data.setId(item.getId());
data.setLabel(item.getLabel());
data.setIsActive(IsActive.Active);
data.setType(ReferenceType.DataRepositories);
data.setCreatedAt(item.getCreated().toInstant());
data.setUpdatedAt(item.getModified().toInstant());
if (item.getCreationUser() != null) data.setCreatedById(item.getCreationUser().getId());
data.setReference(referenceParts[1]);
data.setSource(isInternal? "Internal" : referenceParts[0]);
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
}

View File

@ -0,0 +1,73 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.ReferenceEntity;
import eu.old.eudat.data.dao.entities.ExternalDatasetDao;
import eu.old.eudat.data.entities.DMP;
import eu.old.eudat.data.entities.ExternalDataset;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
@Service
public class ExternalDatasetMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalDatasetMigrationService.class));
private static final int PageSize = 500;
private static final String InternalReferenceSource = "dmp";
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
public ExternalDatasetMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
public void migrate(){
ExternalDatasetDao externalDatasetDao = databaseRepository.getExternalDatasetDao();
long total = externalDatasetDao.asQueryable().count();
logger.debug("Migrate ExternalDataset Total : " + total);
int page = 0;
List<ExternalDataset> items;
do {
items = externalDatasetDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate ExternalDataset " + page * PageSize + " of " + total);
for (ExternalDataset item : items) {
entityManager.detach(item);
if (item.getReference() == null || !item.getReference().contains(":")){
logger.warn("Reference generated because is null ExternalDataset " + item.getId());
item.setReference(InternalReferenceSource + ":" + item.getId().toString().toLowerCase(Locale.ROOT));
}
eu.old.eudat.models.data.externaldataset.ExternalDatasetModel model = new eu.old.eudat.models.data.externaldataset.ExternalDatasetModel().fromDataModel(item);
String[] referenceParts = item.getReference().split(":", 2);
boolean isInternal = referenceParts[0].equals(InternalReferenceSource);
ReferenceEntity data = new ReferenceEntity();
data.setId(item.getId());
data.setLabel(item.getLabel());
data.setIsActive(IsActive.Active);
data.setType(ReferenceType.Datasets);
data.setCreatedAt(item.getCreated().toInstant());
data.setUpdatedAt(item.getModified().toInstant());
if (item.getCreationUser() != null) data.setCreatedById(item.getCreationUser().getId());
data.setReference(referenceParts[1]);
data.setSource(isInternal? "Internal" : referenceParts[0]);
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
}

View File

@ -0,0 +1,73 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.ReferenceEntity;
import eu.old.eudat.data.dao.entities.FunderDao;
import eu.old.eudat.data.entities.DMP;
import eu.old.eudat.data.entities.Funder;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
@Service
public class FunderMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(FunderMigrationService.class));
private static final int PageSize = 500;
private static final String InternalReferenceSource = "dmp";
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
public FunderMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
public void migrate(){
FunderDao funderDao = databaseRepository.getFunderDao();
long total = funderDao.asQueryable().count();
logger.debug("Migrate Funder Total : " + total);
int page = 0;
List<Funder> items;
do {
items = funderDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Funder " + page * PageSize + " of " + total);
for (Funder item : items) {
entityManager.detach(item);
if (item.getReference() == null || !item.getReference().contains(":")){
logger.warn("Reference generated because is null Funder " + item.getId());
item.setReference(InternalReferenceSource + ":" + item.getId().toString().toLowerCase(Locale.ROOT));
}
eu.old.eudat.models.data.funder.Funder model = new eu.old.eudat.models.data.funder.Funder().fromDataModel(item);
String[] referenceParts = item.getReference().split(":", 2);
boolean isInternal = referenceParts[0].equals(InternalReferenceSource);
ReferenceEntity data = new ReferenceEntity();
data.setId(item.getId());
data.setLabel(item.getLabel());
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
data.setType(ReferenceType.Funder);
data.setCreatedAt(item.getCreated().toInstant());
data.setUpdatedAt(item.getModified().toInstant());
if (item.getCreationUser() != null) data.setCreatedById(item.getCreationUser().getId());
data.setReference(referenceParts[1]);
data.setSource(isInternal? "Internal" : referenceParts[0]);
data.setSourceType(Funder.FunderType.INTERNAL.getValue().equals(item.getType())? ReferenceSourceType.Internal : ReferenceSourceType.External);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
}

View File

@ -0,0 +1,73 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.ReferenceEntity;
import eu.old.eudat.data.dao.entities.GrantDao;
import eu.old.eudat.data.entities.DMP;
import eu.old.eudat.data.entities.Grant;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
@Service
public class GrantMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(GrantMigrationService.class));
private static final int PageSize = 500;
private static final String InternalReferenceSource = "dmp";
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
public GrantMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
public void migrate(){
GrantDao grantDao = databaseRepository.getGrantDao();
long total = grantDao.asQueryable().count();
logger.debug("Migrate Grant Total : " + total);
int page = 0;
List<Grant> items;
do {
items = grantDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Grant " + page * PageSize + " of " + total);
for (Grant item : items) {
entityManager.detach(item);
if (item.getReference() == null || !item.getReference().contains(":")){
logger.warn("Reference generated because is null Grant " + item.getId());
item.setReference(InternalReferenceSource + ":" + item.getId().toString().toLowerCase(Locale.ROOT));
}
String[] referenceParts = item.getReference().split(":", 2);
boolean isInternal = referenceParts[0].equals(InternalReferenceSource);
ReferenceEntity data = new ReferenceEntity();
data.setId(item.getId());
data.setLabel(item.getLabel());
data.setDescription(item.getDescription());
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
data.setType(ReferenceType.Grants);
data.setCreatedAt(item.getCreated().toInstant());
data.setUpdatedAt(item.getModified().toInstant());
if (item.getCreationUser() != null) data.setCreatedById(item.getCreationUser().getId());
data.setReference(referenceParts[1]);
data.setSource(isInternal? "Internal" : referenceParts[0]);
data.setSourceType(isInternal ? ReferenceSourceType.Internal : ReferenceSourceType.External);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
}

View File

@ -15,12 +15,13 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@Service
public class OrganizationMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(OrganizationMigrationService.class));
private static final int PageSize = 100;
private static final int PageSize = 500;
private static final String InternalReferenceSource = "Internal";
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
@ -37,16 +38,18 @@ public class OrganizationMigrationService {
List<Organisation> items;
do {
items = organisationDao.asQueryable().orderBy((builder, root) -> builder.desc(root.get("created"))).skip(page * PageSize).take(PageSize).toList();
items = organisationDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Organisation " + page * PageSize + " of " + total);
for (Organisation item : items) {
entityManager.detach(item);
if (item.getReference() == null || !item.getReference().contains(":")){
logger.warn("Reference generated because is null Organisation " + item.getId());
item.setReference(InternalReferenceSource + ":" + item.getId().toString().toLowerCase(Locale.ROOT));
}
eu.old.eudat.models.data.dmp.Organisation model = new eu.old.eudat.models.data.dmp.Organisation().fromDataModel(item);
if (item.getReference() == null || !item.getReference().contains(":")){
logger.debug("Can not migrate Organisation " + item.getId());
continue;
}
String[] referenceParts = item.getReference().split(":", 2);
boolean isInternal = referenceParts[0].equals(InternalReferenceSource);
@ -59,7 +62,7 @@ public class OrganizationMigrationService {
data.setUpdatedAt(item.getModified().toInstant());
data.setReference(referenceParts[1]);
data.setAbbreviation(item.getAbbreviation());
data.setSource(referenceParts[0]);
data.setSource(isInternal? "Internal" : referenceParts[0]);
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
this.entityManager.persist(data);
}

View File

@ -0,0 +1,74 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.ReferenceEntity;
import eu.old.eudat.data.dao.entities.ProjectDao;
import eu.old.eudat.data.entities.DMP;
import eu.old.eudat.data.entities.Project;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
@Service
public class ProjectMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ProjectMigrationService.class));
private static final int PageSize = 500;
private static final String InternalReferenceSource = "dmp";
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
public ProjectMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
public void migrate(){
ProjectDao projectDao = databaseRepository.getProjectDao();
long total = projectDao.asQueryable().count();
logger.debug("Migrate Project Total : " + total);
int page = 0;
List<Project> items;
do {
items = projectDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Project " + page * PageSize + " of " + total);
for (Project item : items) {
entityManager.detach(item);
if (item.getReference() == null || !item.getReference().contains(":")){
logger.warn("Reference generated because is null Project " + item.getId());
item.setReference(InternalReferenceSource + ":" + item.getId().toString().toLowerCase(Locale.ROOT));
}
eu.old.eudat.models.data.project.Project model = new eu.old.eudat.models.data.project.Project().fromDataModel(item);
String[] referenceParts = item.getReference().split(":", 2);
boolean isInternal = referenceParts[0].equals(InternalReferenceSource);
ReferenceEntity data = new ReferenceEntity();
data.setId(item.getId());
data.setLabel(item.getLabel());
data.setDescription(item.getDescription());
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
data.setType(ReferenceType.Project);
data.setCreatedAt(item.getCreated().toInstant());
data.setUpdatedAt(item.getModified().toInstant());
if (item.getCreationUser() != null) data.setCreatedById(item.getCreationUser().getId());
data.setReference(referenceParts[1]);
data.setSource(isInternal? "Internal" : referenceParts[0]);
data.setSourceType(Project.ProjectType.INTERNAL.getValue().equals(item.getType())? ReferenceSourceType.Internal : ReferenceSourceType.External);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
}

View File

@ -0,0 +1,73 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.ReferenceEntity;
import eu.old.eudat.data.dao.entities.RegistryDao;
import eu.old.eudat.data.entities.DMP;
import eu.old.eudat.data.entities.Registry;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
@Service
public class RegistryMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(RegistryMigrationService.class));
private static final int PageSize = 500;
private static final String InternalReferenceSource = "dmp";
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
public RegistryMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
public void migrate(){
RegistryDao registryDao = databaseRepository.getRegistryDao();
long total = registryDao.asQueryable().count();
logger.debug("Migrate Registry Total : " + total);
int page = 0;
List<Registry> items;
do {
items = registryDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Registry " + page * PageSize + " of " + total);
for (Registry item : items) {
entityManager.detach(item);
if (item.getReference() == null || !item.getReference().contains(":")){
logger.warn("Reference generated because is null Registry " + item.getId());
item.setReference(InternalReferenceSource + ":" + item.getId().toString().toLowerCase(Locale.ROOT));
}
eu.old.eudat.models.data.registries.RegistryModel model = new eu.old.eudat.models.data.registries.RegistryModel().fromDataModel(item);
String[] referenceParts = item.getReference().split(":", 2);
boolean isInternal = referenceParts[0].equals(InternalReferenceSource);
ReferenceEntity data = new ReferenceEntity();
data.setId(item.getId());
data.setLabel(item.getLabel());
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
data.setType(ReferenceType.Registries);
data.setCreatedAt(item.getCreated().toInstant());
data.setUpdatedAt(item.getModified().toInstant());
if (item.getCreationUser() != null) data.setCreatedById(item.getCreationUser().getId());
data.setReference(referenceParts[1]);
data.setSource(isInternal? "Internal" : referenceParts[0]);
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
}

View File

@ -0,0 +1,75 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.ReferenceEntity;
import eu.old.eudat.data.dao.entities.OrganisationDao;
import eu.old.eudat.data.dao.entities.ResearcherDao;
import eu.old.eudat.data.entities.DMP;
import eu.old.eudat.data.entities.Organisation;
import eu.old.eudat.data.entities.Researcher;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
@Service
public class ResearcherMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ResearcherMigrationService.class));
private static final int PageSize = 500;
private static final String InternalReferenceSource = "dmp";
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
public ResearcherMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
public void migrate(){
ResearcherDao researcherDao = databaseRepository.getResearcherDao();
long total = researcherDao.asQueryable().count();
logger.debug("Migrate Researcher Total : " + total);
int page = 0;
List<Researcher> items;
do {
items = researcherDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Researcher " + page * PageSize + " of " + total);
for (Researcher item : items) {
entityManager.detach(item);
if (item.getReference() == null || !item.getReference().contains(":")){
logger.warn("Reference generated because is null Researcher " + item.getId());
item.setReference(InternalReferenceSource + ":" + item.getId().toString().toLowerCase(Locale.ROOT));
}
eu.old.eudat.models.data.dmp.Researcher model = new eu.old.eudat.models.data.dmp.Researcher().fromDataModel(item);
String[] referenceParts = item.getReference().split(":", 2);
boolean isInternal = referenceParts[0].equals(InternalReferenceSource);
ReferenceEntity data = new ReferenceEntity();
data.setId(item.getId());
data.setLabel(item.getLabel());
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
data.setType(ReferenceType.Researcher);
data.setCreatedAt(item.getCreated().toInstant());
data.setUpdatedAt(item.getModified().toInstant());
if (item.getCreationUser() != null) data.setCreatedById(item.getCreationUser().getId());
data.setReference(referenceParts[1]);
data.setSource(isInternal? "Internal" : referenceParts[0]);
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
}

View File

@ -0,0 +1,73 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.ReferenceEntity;
import eu.old.eudat.data.dao.entities.ServiceDao;
import eu.old.eudat.data.entities.DMP;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Locale;
@Service
public class ServiceMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ServiceMigrationService.class));
private static final int PageSize = 500;
private static final String InternalReferenceSource = "dmp";
private final DatabaseRepository databaseRepository;
private final EntityManager entityManager;
public ServiceMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.entityManager = entityManager;
}
public void migrate(){
ServiceDao serviceDao = databaseRepository.getServiceDao();
long total = serviceDao.asQueryable().count();
logger.debug("Migrate Service Total : " + total);
int page = 0;
List<eu.old.eudat.data.entities.Service> items;
do {
items = serviceDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Service " + page * PageSize + " of " + total);
for (eu.old.eudat.data.entities.Service item : items) {
entityManager.detach(item);
if (item.getReference() == null || !item.getReference().contains(":")){
logger.warn("Reference generated because is null Service " + item.getId());
item.setReference(InternalReferenceSource + ":" + item.getId().toString().toLowerCase(Locale.ROOT));
}
eu.old.eudat.models.data.services.ServiceModel model = new eu.old.eudat.models.data.services.ServiceModel().fromDataModel(item);
String[] referenceParts = item.getReference().split(":", 2);
boolean isInternal = referenceParts[0].equals(InternalReferenceSource);
ReferenceEntity data = new ReferenceEntity();
data.setId(item.getId());
data.setLabel(item.getLabel());
data.setDescription(item.getLabel());
data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active);
data.setType(ReferenceType.Services);
data.setCreatedAt(item.getCreated().toInstant());
data.setUpdatedAt(item.getModified().toInstant());
if (item.getCreationUser() != null) data.setCreatedById(item.getCreationUser().getId());
data.setReference(referenceParts[1]);
data.setSource(isInternal? "Internal" : referenceParts[0]);
data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
}

View File

@ -1,14 +1,8 @@
package eu.old.eudat.publicapi.migration;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.data.DmpEntity;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import eu.old.eudat.migration.DmpMigrationService;
import eu.old.eudat.migration.OrganizationMigrationService;
import eu.old.eudat.migration.*;
import io.swagger.annotations.Api;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@ -19,11 +13,38 @@ import org.springframework.web.bind.annotation.*;
public class MigrationController {
private final DmpMigrationService dmpMigrationService;
private final DataRepositoryMigrationService dataRepositoryMigrationService;
private final ExternalDatasetMigrationService externalDatasetMigrationService;
private final FunderMigrationService funderMigrationService;
private final GrantMigrationService grantMigrationService;
private final ProjectMigrationService projectMigrationService;
private final RegistryMigrationService registryMigrationService;
private final ResearcherMigrationService researcherMigrationService;
private final ServiceMigrationService serviceMigrationService;
private final OrganizationMigrationService organizationMigrationService;
public MigrationController(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager, DmpMigrationService dmpMigrationService, OrganizationMigrationService organizationMigrationService) {
public MigrationController(
DmpMigrationService dmpMigrationService,
DataRepositoryMigrationService dataRepositoryMigrationService,
ExternalDatasetMigrationService externalDatasetMigrationService,
FunderMigrationService funderMigrationService,
GrantMigrationService grantMigrationService,
ProjectMigrationService projectMigrationService,
RegistryMigrationService registryMigrationService,
ResearcherMigrationService researcherMigrationService,
ServiceMigrationService serviceMigrationService,
OrganizationMigrationService organizationMigrationService
) {
this.dmpMigrationService = dmpMigrationService;
this.dataRepositoryMigrationService = dataRepositoryMigrationService;
this.externalDatasetMigrationService = externalDatasetMigrationService;
this.funderMigrationService = funderMigrationService;
this.grantMigrationService = grantMigrationService;
this.projectMigrationService = projectMigrationService;
this.registryMigrationService = registryMigrationService;
this.researcherMigrationService = researcherMigrationService;
this.serviceMigrationService = serviceMigrationService;
this.organizationMigrationService = organizationMigrationService;
}
@ -33,11 +54,82 @@ public class MigrationController {
return this.dmpMigrationService.migrate();
}
@GetMapping("organizations/migrate")
@GetMapping("organizations")
@Transactional
public boolean migrateOrganizations() {
this.organizationMigrationService.migrate();
return true;
}
@GetMapping("references")
@Transactional
public boolean migrateReferences() {
this.dataRepositoryMigrationService.migrate();
this.externalDatasetMigrationService.migrate();
this.funderMigrationService.migrate();
this.grantMigrationService.migrate();
this.organizationMigrationService.migrate();
this.projectMigrationService.migrate();
this.registryMigrationService.migrate();
this.researcherMigrationService.migrate();
this.serviceMigrationService.migrate();
return true;
}
@GetMapping("dataRepositories")
@Transactional
public boolean migrateDataRepositories() {
this.dataRepositoryMigrationService.migrate();
return true;
}
@GetMapping("externalDatasets")
@Transactional
public boolean migrateExternalDatasets() {
this.externalDatasetMigrationService.migrate();
return true;
}
@GetMapping("funders")
@Transactional
public boolean migrateFunders() {
this.funderMigrationService.migrate();
return true;
}
@GetMapping("grants")
@Transactional
public boolean migrateGrants() {
this.grantMigrationService.migrate();
return true;
}
@GetMapping("projects")
@Transactional
public boolean migrateProjects() {
this.projectMigrationService.migrate();
return true;
}
@GetMapping("registries")
@Transactional
public boolean migrateRegistries() {
this.registryMigrationService.migrate();
return true;
}
@GetMapping("researchers")
@Transactional
public boolean migrateResearchers() {
this.researcherMigrationService.migrate();
return true;
}
@GetMapping("services")
@Transactional
public boolean migrateServices() {
this.serviceMigrationService.migrate();
return true;
}
}

View File

@ -30,8 +30,8 @@ admin.mail.subject=You have been invited to the Dataset Template {templateName}
####################SPRING MAIL CONFIGURATIONS#################
spring.mail.default-encoding=UTF-8
spring.mail.host=hermes.local.cite.gr
spring.mail.port=25
spring.mail.host=
spring.mail.port=
spring.mail.protocol=smtp
spring.mail.test-connection=false
spring.mail.properties.mail.smtp.auth=false