diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java b/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java index 5cefc1137..487305e56 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java @@ -291,19 +291,25 @@ public class Dataset implements DataEntity { @Override public void update(Dataset entity) { this.setRegistries(entity.getRegistries()); - this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); - this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().map(item->{ - item.setDataset(this); - return item; - }).collect(Collectors.toList())); + if(this.getDatasetDataRepositories()==null) this.setDatasetDataRepositories(new HashSet<>()); + if(!this.getDatasetDataRepositories().containsAll(entity.getDatasetDataRepositories())){ + this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); + this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().map(item->{ + item.setDataset(this); + return item; + }).collect(Collectors.toList())); + } this.setDescription(entity.getDescription()); this.setLabel(entity.getLabel()); this.setProperties(entity.getProperties()); - this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); - this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().map(item -> { - item.setDataset(this); - return item; - }).collect(Collectors.toList())); + if(this.getDatasetExternalDatasets()==null) this.setDatasetExternalDatasets(new HashSet<>()); + if(!this.getDatasetExternalDatasets().containsAll(entity.getDatasetExternalDatasets())) { + this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); + this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().map(item -> { + item.setDataset(this); + return item; + }).collect(Collectors.toList())); + } this.setStatus(entity.getStatus()); this.setProfile(entity.getProfile()); this.setModified(new Date()); diff --git a/dmp-backend/logging/pom.xml b/dmp-backend/logging/pom.xml new file mode 100644 index 000000000..872ec0288 --- /dev/null +++ b/dmp-backend/logging/pom.xml @@ -0,0 +1,23 @@ + + + + 4.0.0 + dmp-backend + logging + 1.0-SNAPSHOT + jar + + eu.eudat + dmp-backend + 1.0.0-SNAPSHOT + + + + org.springframework + spring-web + 5.0.6.RELEASE + + + \ No newline at end of file diff --git a/dmp-backend/logging/src/main/java/eu/eudat/core/logger/Logger.java b/dmp-backend/logging/src/main/java/eu/eudat/core/logger/Logger.java new file mode 100644 index 000000000..2595f2911 --- /dev/null +++ b/dmp-backend/logging/src/main/java/eu/eudat/core/logger/Logger.java @@ -0,0 +1,41 @@ +package eu.eudat.core.logger; + +/** + * Created by ikalyvas on 5/30/2018. + */ +public interface Logger { + + void debug(T model); + + void debug(T model,String message); + + void debug(String message); + + void debug(T exception); + + void debug(T exception,String message); + + void warn(T model); + + void warn(T model,String message); + + void warn(String message); + + void warn(T exception); + + void warn(T exception,String message); + + void info(T model); + + void info(T model,String message); + + void info(T exception); + + void info(T exception,String message); + + void error(T loggingModel); + + void error(T exception); + + void error(T exception,String message); +} diff --git a/dmp-backend/logging/src/main/java/eu/eudat/core/logger/common/AbstractBatchLogger.java b/dmp-backend/logging/src/main/java/eu/eudat/core/logger/common/AbstractBatchLogger.java new file mode 100644 index 000000000..229af61ec --- /dev/null +++ b/dmp-backend/logging/src/main/java/eu/eudat/core/logger/common/AbstractBatchLogger.java @@ -0,0 +1,55 @@ +package eu.eudat.core.logger.common; + +import org.json.JSONObject; +import org.springframework.core.env.Environment; +import types.LoggingOutputType; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +/** + * Created by ikalyvas on 5/30/2018. + */ +public abstract class AbstractBatchLogger { + private Map concurrentHashMap = new ConcurrentHashMap(); + + public AbstractBatchLogger(Environment environment) { + ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); + + executor.scheduleAtFixedRate(() -> this.outputData(), Long.parseLong(environment.getProperty("http-logger.initial-delay")), Long.parseLong(environment.getProperty("http-logger.delay")), TimeUnit.SECONDS); + } + + public abstract LoggingOutputType logOutputType(); + + public void put(String key, T data) { + this.concurrentHashMap.put(key, data); + } + + public void clear() { + this.concurrentHashMap.clear(); + } + + private Map getAndClear() { + Map map = new HashMap<>(); + map.putAll(this.concurrentHashMap); + this.concurrentHashMap.keySet().removeAll(map.keySet()); + return map; + } + + public String tranformLog() { + Map> transformedMap = new HashMap<>(); + transformedMap.put("data",this.getAndClear().values()); + if (this.logOutputType().equals(LoggingOutputType.JSON)) + return this.concurrentHashMap.values().size() > 0 ? new JSONObject(transformedMap).toString() : null; + if (this.logOutputType().equals(LoggingOutputType.FILE)) + return this.concurrentHashMap.toString(); //TODO actual implementation of file Logger + else throw new RuntimeException("Unsupported LoggingOutputType type"); + } + + public abstract void outputData(); +} diff --git a/dmp-backend/logging/src/main/java/eu/eudat/core/logger/remote/http/HttpRemoteLogger.java b/dmp-backend/logging/src/main/java/eu/eudat/core/logger/remote/http/HttpRemoteLogger.java new file mode 100644 index 000000000..3d90f1848 --- /dev/null +++ b/dmp-backend/logging/src/main/java/eu/eudat/core/logger/remote/http/HttpRemoteLogger.java @@ -0,0 +1,196 @@ +package eu.eudat.core.logger.remote.http; + +import eu.eudat.core.logger.Logger; +import eu.eudat.core.logger.common.AbstractBatchLogger; +import eu.eudat.core.models.LoggingModel; +import eu.eudat.core.models.exception.ExceptionLoggingModel; +import eu.eudat.core.models.simple.SimpleAuditModel; +import eu.eudat.core.models.simple.SimpleLoggingModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; +import types.LoggingOutputType; +import types.LoggingType; + +/** + * Created by ikalyvas on 5/30/2018. + */ + +@Service("logger") +public class HttpRemoteLogger extends AbstractBatchLogger implements Logger { + + private RestTemplate rest; + private HttpHeaders headers; + private Environment environment; + + @Autowired + public HttpRemoteLogger(Environment environment) { + super(environment); + this.rest = new RestTemplate(); + this.headers = new HttpHeaders(); + this.environment = environment; + headers.add("Content-Type", "application/json"); + headers.add("Accept", "*/*"); + } + + @Override + public void outputData() { + String log = this.tranformLog(); + if (log != null && !log.isEmpty()) { + HttpEntity requestEntity = new HttpEntity(log, headers); + ResponseEntity responseEntity = rest.exchange(this.environment.getProperty("http-logger.server-address"), HttpMethod.POST, requestEntity, String.class); + } + } + + @Override + public LoggingOutputType logOutputType() { + return LoggingOutputType.JSON; + } + + @Override + public void debug(T model) { + LoggingModel loggingModel = new SimpleLoggingModel<>(); + loggingModel.setData(model); + loggingModel.setType(LoggingType.DEBUG); + this.put(String.valueOf(model.hashCode()), loggingModel); + } + + @Override + public void debug(T model, String message) { + LoggingModel loggingModel = new SimpleLoggingModel<>(); + loggingModel.setData(model); + loggingModel.setMessage(message); + loggingModel.setType(LoggingType.DEBUG); + this.put(String.valueOf(model.hashCode()), loggingModel); + } + + @Override + public void debug(String message) { + LoggingModel loggingModel = new SimpleLoggingModel<>(); + loggingModel.setMessage(message); + loggingModel.setType(LoggingType.DEBUG); + this.put(String.valueOf(message.hashCode()), loggingModel); + } + + @Override + public void debug(T exception) { + ExceptionLoggingModel loggingModel = new ExceptionLoggingModel<>(); + loggingModel.setData(exception); + loggingModel.setType(LoggingType.DEBUG); + this.put(String.valueOf(exception.hashCode()), loggingModel); + } + + @Override + public void debug(T exception, String message) { + ExceptionLoggingModel loggingModel = new ExceptionLoggingModel<>(); + loggingModel.setData(exception); + loggingModel.setMessage(message); + loggingModel.setType(LoggingType.DEBUG); + this.put(String.valueOf(exception.hashCode()), loggingModel); + } + + @Override + public void warn(T model) { + LoggingModel loggingModel = new SimpleLoggingModel<>(); + loggingModel.setData(model); + loggingModel.setType(LoggingType.WARNING); + this.put(String.valueOf(model.hashCode()), loggingModel); + } + + @Override + public void warn(T model, String message) { + LoggingModel loggingModel = new SimpleLoggingModel<>(); + loggingModel.setData(model); + loggingModel.setMessage(message); + loggingModel.setType(LoggingType.WARNING); + this.put(String.valueOf(model.hashCode()), loggingModel); + } + + @Override + public void warn(String message) { + LoggingModel loggingModel = new SimpleLoggingModel<>(); + loggingModel.setMessage(message); + loggingModel.setType(LoggingType.WARNING); + this.put(String.valueOf(message.hashCode()), loggingModel); + } + + @Override + public void warn(T exception) { + ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel<>(); + exceptionLoggingModel.setData(exception); + exceptionLoggingModel.setType(LoggingType.WARNING); + this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel); + } + + @Override + public void warn(T exception, String message) { + ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel<>(); + exceptionLoggingModel.setData(exception); + exceptionLoggingModel.setMessage(message); + exceptionLoggingModel.setType(LoggingType.WARNING); + this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel); + } + + @Override + public void info(T model) { + SimpleAuditModel simpleAuditModel = new SimpleAuditModel<>(); + simpleAuditModel.setData(model); + simpleAuditModel.setType(LoggingType.INFO); + this.put(String.valueOf(model.hashCode()), simpleAuditModel); + } + + @Override + public void info(T model, String message) { + SimpleAuditModel simpleAuditModel = new SimpleAuditModel<>(); + simpleAuditModel.setData(model); + simpleAuditModel.setMessage(message); + simpleAuditModel.setType(LoggingType.INFO); + this.put(String.valueOf(model.hashCode()), simpleAuditModel); + } + + @Override + public void info(T exception) { + ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel<>(); + exceptionLoggingModel.setData(exception); + exceptionLoggingModel.setType(LoggingType.INFO); + this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel); + } + + @Override + public void info(T exception, String message) { + ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel<>(); + exceptionLoggingModel.setData(exception); + exceptionLoggingModel.setMessage(message); + exceptionLoggingModel.setType(LoggingType.INFO); + this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel); + } + + @Override + public void error(T model) { + LoggingModel loggingModel = new SimpleLoggingModel<>(); + loggingModel.setType(LoggingType.DEBUG); + this.put(String.valueOf(model.hashCode()), loggingModel); + } + + @Override + public void error(T exception) { + ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel<>(); + exceptionLoggingModel.setData(exception); + exceptionLoggingModel.setType(LoggingType.ERROR); + this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel); + } + + @Override + public void error(T exception, String message) { + ExceptionLoggingModel exceptionLoggingModel = new ExceptionLoggingModel<>(); + exceptionLoggingModel.setData(exception); + exceptionLoggingModel.setMessage(message); + exceptionLoggingModel.setType(LoggingType.ERROR); + this.put(String.valueOf(exception.hashCode()), exceptionLoggingModel); + } +} diff --git a/dmp-backend/logging/src/main/java/eu/eudat/core/models/AuditModel.java b/dmp-backend/logging/src/main/java/eu/eudat/core/models/AuditModel.java new file mode 100644 index 000000000..3cf41edb1 --- /dev/null +++ b/dmp-backend/logging/src/main/java/eu/eudat/core/models/AuditModel.java @@ -0,0 +1,8 @@ +package eu.eudat.core.models; + +/** + * Created by ikalyvas on 5/30/2018. + */ +public abstract class AuditModel extends LoggingModel{ + +} diff --git a/dmp-backend/logging/src/main/java/eu/eudat/core/models/LoggingModel.java b/dmp-backend/logging/src/main/java/eu/eudat/core/models/LoggingModel.java new file mode 100644 index 000000000..177721050 --- /dev/null +++ b/dmp-backend/logging/src/main/java/eu/eudat/core/models/LoggingModel.java @@ -0,0 +1,36 @@ +package eu.eudat.core.models; + +import types.LoggingType; + +/** + * Created by ikalyvas on 5/30/2018. + */ +public abstract class LoggingModel { + private T data; + private LoggingType type; + private String message; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + public LoggingType getType() { + return type; + } + + public void setType(LoggingType type) { + this.type = type; + } +} diff --git a/dmp-backend/logging/src/main/java/eu/eudat/core/models/exception/ExceptionLoggingModel.java b/dmp-backend/logging/src/main/java/eu/eudat/core/models/exception/ExceptionLoggingModel.java new file mode 100644 index 000000000..f892fa9d5 --- /dev/null +++ b/dmp-backend/logging/src/main/java/eu/eudat/core/models/exception/ExceptionLoggingModel.java @@ -0,0 +1,9 @@ +package eu.eudat.core.models.exception; + +import eu.eudat.core.models.LoggingModel; + +/** + * Created by ikalyvas on 5/30/2018. + */ +public class ExceptionLoggingModel extends LoggingModel { +} diff --git a/dmp-backend/logging/src/main/java/eu/eudat/core/models/simple/SimpleAuditModel.java b/dmp-backend/logging/src/main/java/eu/eudat/core/models/simple/SimpleAuditModel.java new file mode 100644 index 000000000..65b38e9b3 --- /dev/null +++ b/dmp-backend/logging/src/main/java/eu/eudat/core/models/simple/SimpleAuditModel.java @@ -0,0 +1,9 @@ +package eu.eudat.core.models.simple; + +import eu.eudat.core.models.AuditModel; + +/** + * Created by ikalyvas on 5/30/2018. + */ +public class SimpleAuditModel extends AuditModel { +} diff --git a/dmp-backend/logging/src/main/java/eu/eudat/core/models/simple/SimpleLoggingModel.java b/dmp-backend/logging/src/main/java/eu/eudat/core/models/simple/SimpleLoggingModel.java new file mode 100644 index 000000000..6a2ff0dae --- /dev/null +++ b/dmp-backend/logging/src/main/java/eu/eudat/core/models/simple/SimpleLoggingModel.java @@ -0,0 +1,9 @@ +package eu.eudat.core.models.simple; + +import eu.eudat.core.models.LoggingModel; + +/** + * Created by ikalyvas on 5/30/2018. + */ +public class SimpleLoggingModel extends LoggingModel { +} diff --git a/dmp-backend/logging/src/main/java/types/LoggingOutputType.java b/dmp-backend/logging/src/main/java/types/LoggingOutputType.java new file mode 100644 index 000000000..279091fe8 --- /dev/null +++ b/dmp-backend/logging/src/main/java/types/LoggingOutputType.java @@ -0,0 +1,29 @@ +package types; + +/** + * Created by ikalyvas on 5/30/2018. + */ +public enum LoggingOutputType { + FILE(0), JSON(1); + + private Integer value; + + private LoggingOutputType(Integer value) { + this.value = value; + } + + public Integer getValue() { + return value; + } + + public static LoggingOutputType fromInteger(Integer value) { + switch (value) { + case 0: + return FILE; + case 1: + return JSON; + default: + throw new RuntimeException("Unsupported Logging LoggingOutputType"); + } + } +} diff --git a/dmp-backend/logging/src/main/java/types/LoggingType.java b/dmp-backend/logging/src/main/java/types/LoggingType.java new file mode 100644 index 000000000..a19980f05 --- /dev/null +++ b/dmp-backend/logging/src/main/java/types/LoggingType.java @@ -0,0 +1,33 @@ +package types; + +/** + * Created by ikalyvas on 5/30/2018. + */ +public enum LoggingType { + WARNING(0), ERROR(1), INFO(2), DEBUG(3); + + private Integer value; + + private LoggingType(Integer value) { + this.value = value; + } + + public Integer getValue() { + return value; + } + + public static LoggingType fromInteger(Integer value) { + switch (value) { + case 0: + return WARNING; + case 1: + return ERROR; + case 2: + return INFO; + case 3: + return DEBUG; + default: + throw new RuntimeException("Unsupported LoggingType"); + } + } +} diff --git a/dmp-backend/pom.xml b/dmp-backend/pom.xml index 70a52797f..edbc404d3 100644 --- a/dmp-backend/pom.xml +++ b/dmp-backend/pom.xml @@ -17,6 +17,7 @@ queryable web data + logging @@ -66,7 +67,7 @@ org.hibernate - hibernate-core + hibernate-eu.eudat.core ${hibernate.version} @@ -98,21 +99,21 @@ - + - com.fasterxml.jackson.core - jackson-core + com.fasterxml.jackson.eu.eudat.core + jackson-eu.eudat.core 2.9.4 - + - com.fasterxml.jackson.core + com.fasterxml.jackson.eu.eudat.core jackson-databind 2.9.4 - + @@ -147,10 +148,10 @@ org.apache.poi.xwpf.converter.pdf 1.0.6 - + fr.opensagres.xdocreport - org.apache.poi.xwpf.converter.core + org.apache.poi.xwpf.converter.eu.eudat.core 1.0.6 diff --git a/dmp-backend/web/pom.xml b/dmp-backend/web/pom.xml index fbd5f6e04..d196e05b2 100644 --- a/dmp-backend/web/pom.xml +++ b/dmp-backend/web/pom.xml @@ -21,6 +21,11 @@ data 1.0-SNAPSHOT + + dmp-backend + logging + 1.0-SNAPSHOT + dmp-backend queryable diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java index 9f0f20579..c7f25e294 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java @@ -1,5 +1,6 @@ package eu.eudat.controllers; +import eu.eudat.core.logger.Logger; import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.managers.UserManager; import eu.eudat.models.helpers.responses.ResponseItem; @@ -35,12 +36,16 @@ public class Login { private B2AccessTokenValidator b2AccessTokenValidator; + private Logger logger; + @Autowired - public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationServiceImpl authenticationServiceImpl, TwitterTokenValidator twitterTokenValidator, B2AccessTokenValidator b2AccessTokenValidator) { + public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationServiceImpl authenticationServiceImpl, + TwitterTokenValidator twitterTokenValidator, B2AccessTokenValidator b2AccessTokenValidator,Logger logger) { this.customAuthenticationProvider = customAuthenticationProvider; this.authenticationServiceImpl = authenticationServiceImpl; this.twitterTokenValidator = twitterTokenValidator; this.b2AccessTokenValidator = b2AccessTokenValidator; + this.logger = logger; } @Transactional @@ -111,9 +116,11 @@ public class Login { ResponseEntity> logout(Principal principal) { try { this.authenticationServiceImpl.Logout(principal.getToken()); + this.logger.info(principal,"Logged Out"); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } catch (Exception ex) { + this.logger.debug(ex,ex.getMessage()); ex.printStackTrace(); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage())); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/managers/ProjectManager.java b/dmp-backend/web/src/main/java/eu/eudat/managers/ProjectManager.java index 825b20e6c..e1f2f694a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/managers/ProjectManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/managers/ProjectManager.java @@ -103,18 +103,20 @@ public class ProjectManager { public static void createOrUpdate(FileStorageService fileStorageService, ProjectDao projectRepository, ContentDao contentRepository, UserInfoDao userInfoRepository, eu.eudat.models.project.Project project, Principal principal) throws ParseException, IOException { eu.eudat.data.entities.Project projectEntity = project.toDataModel(); - for (ContentFile file : project.getFiles()) { - try { - ContentFile storedFile = fileStorageService.copyFromTempFileSystem(file); - Content content = new ContentBuilder().extension(file.getType()) - .label(file.getFilename()) - .locationType(Content.LocationType.INTERNAL.getValue()) - .parentType(Content.ParentType.PROJECT.getValue()) - .uri("LOCAL:" + storedFile.getId()) - .build(); - projectEntity.setContent(contentRepository.createOrUpdate(content)); - } catch (TempFileNotFoundException e) { - continue; + if(project.getFiles() != null) { + for (ContentFile file : project.getFiles()) { + try { + ContentFile storedFile = fileStorageService.copyFromTempFileSystem(file); + Content content = new ContentBuilder().extension(file.getType()) + .label(file.getFilename()) + .locationType(Content.LocationType.INTERNAL.getValue()) + .parentType(Content.ParentType.PROJECT.getValue()) + .uri("LOCAL:" + storedFile.getId()) + .build(); + projectEntity.setContent(contentRepository.createOrUpdate(content)); + } catch (TempFileNotFoundException e) { + continue; + } } } projectEntity.setType(eu.eudat.data.entities.Project.ProjectType.INTERNAL.getValue()); diff --git a/dmp-backend/web/src/main/resources/application.properties b/dmp-backend/web/src/main/resources/application.properties index 82bcaf14b..80c778cce 100644 --- a/dmp-backend/web/src/main/resources/application.properties +++ b/dmp-backend/web/src/main/resources/application.properties @@ -65,4 +65,8 @@ files.storage.final = final ################################################################################# project.configuration.project.name = Project project.configuration.funder.name = Funder -project.configuration.grant.name = Grant \ No newline at end of file +project.configuration.grant.name = Grant +################################################################################# +http-logger.initial-delay = 0 +http-logger.delay = 10 +http-logger.server-address = http://localhost:31311 \ No newline at end of file diff --git a/dmp-frontend/src/app/app.module.ts b/dmp-frontend/src/app/app.module.ts index 545323d9d..658077f76 100644 --- a/dmp-frontend/src/app/app.module.ts +++ b/dmp-frontend/src/app/app.module.ts @@ -40,6 +40,7 @@ import { LanguageService } from './services/language/language.service'; import { UsersModule } from './users/users.module'; import { HelpContentComponent } from './shared/help-content/help-content.component'; import { AuthGuard } from './shared/guards/auth.guard'; +import { UrlUtilities } from './utilities/UrlUtilities'; @NgModule({ declarations: [ @@ -96,7 +97,7 @@ import { AuthGuard } from './shared/guards/auth.guard'; clientId: "eudatdmptool", clientSecret: "A3b*1*92", oauthUrl: "https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz", - redirectUri: "http://dl043.madgik.di.uoa.gr:8080/api/oauth/authorized/b2access", + redirectUri: "http://dl043.madgik.di.uoa.gr/api/oauth/authorized/b2access", accessTokenUri: "https://b2access-integration.fz-juelich.de:443/oauth2/token" } }), @@ -106,7 +107,7 @@ import { AuthGuard } from './shared/guards/auth.guard'; AuthGuard, AuthService, BaseHttpService, - + UrlUtilities, DashboardService, HelpContentService, LanguageService, diff --git a/dmp-frontend/src/app/datasets/dataset-wizard/dataset-wizard.component.html b/dmp-frontend/src/app/datasets/dataset-wizard/dataset-wizard.component.html index 23a2443db..66120e7b9 100644 --- a/dmp-frontend/src/app/datasets/dataset-wizard/dataset-wizard.component.html +++ b/dmp-frontend/src/app/datasets/dataset-wizard/dataset-wizard.component.html @@ -46,90 +46,131 @@
{{'DATASET-WIZARD.SECOND-STEP.TITLE' | translate}} - + + + + {{'DATASET-EDITOR.FIELDS.DATAREPOSITORIES' | translate}} + + + - + - -
-

- {{suggestion.get('name').value}} -

-
-
- - + +
+

+ {{i+1}}) {{suggestion.get('name').value}} +

+
+
+ + - -
-
+
+
+
+ +
+
+ + + + + {{'DATASET-EDITOR.FIELDS.EXTERNAL-DATASETS' | translate}} + + + - + - + +
+

+ {{i+1}}) {{suggestion.get('label').value}} +

+
+
+ + - -
-

- {{suggestion.get('label').value}} -

-
-
- - + +
-
-
-
- - - {{'TYPES.EXTERNAL-DATASET-TYPE.SOURCE' | translate}} - {{'TYPES.EXTERNAL-DATASET-TYPE.OUTPUT' | translate}} - - -
+
+ + + {{'TYPES.EXTERNAL-DATASET-TYPE.SOURCE' | translate}} + {{'TYPES.EXTERNAL-DATASET-TYPE.OUTPUT' | translate}} + + +
+
+ +
+
+
- + + + + {{'DATASET-EDITOR.FIELDS.REGISTRIES' | translate}} + + + + + +
+

+ {{i+1}}) {{suggestion.get('label').value}} +

+
+
+ +
+
+
- + + + + {{'DATASET-EDITOR.FIELDS.SERVICES' | translate}} + + + - - - -
-

- {{suggestion.get('label').value}} -

-
- -
- - - - - - - -
-

- {{suggestion.get('label').value}} -

-
- -
+
+ +
+

+ {{i+1}}) {{suggestion.get('label').value}} +

+
+
+ +
+
+
diff --git a/dmp-frontend/src/app/datasets/listing/dataset-listing.component.html b/dmp-frontend/src/app/datasets/listing/dataset-listing.component.html index 8bf90cb2a..c7c67040c 100644 --- a/dmp-frontend/src/app/datasets/listing/dataset-listing.component.html +++ b/dmp-frontend/src/app/datasets/listing/dataset-listing.component.html @@ -1,96 +1,96 @@
-

{{'DATASET-LISTING.TITLE' | translate}} {{titlePrefix}}

+

{{'DATASET-LISTING.TITLE' | translate}} {{titlePrefix}}

- - - - - - + + + + + + - - - {{'DATASET-LISTING.COLUMNS.NAME' | translate}} - {{row.label}} - + + + {{'DATASET-LISTING.COLUMNS.NAME' | translate}} + {{row.label}} + - - - {{'DATASET-LISTING.COLUMNS.DMP' | translate}} - {{row.dmp}} - + + + {{'DATASET-LISTING.COLUMNS.DMP' | translate}} + {{row.dmp}} + - - - {{'DATASET-LISTING.COLUMNS.PROFILE' | translate}} - {{row.profile}} - + + + {{'DATASET-LISTING.COLUMNS.PROFILE' | translate}} + {{row.profile}} + - - - {{'DATASET-LISTING.COLUMNS.DATAREPOSITORIES' | translate}} - {{row.dataRepositories}} - + + + {{'DATASET-LISTING.COLUMNS.DATAREPOSITORIES' | translate}} + {{row.dataRepositories}} + - - - {{'DATASET-LISTING.COLUMNS.REGISTRIES' | translate}} - {{row.registries}} - + + + {{'DATASET-LISTING.COLUMNS.REGISTRIES' | translate}} + {{row.registries}} + - - - {{'DATASET-LISTING.COLUMNS.SERVICES' | translate}} - {{row.services}} - + + + {{'DATASET-LISTING.COLUMNS.SERVICES' | translate}} + {{row.services}} + - - + - - - {{'DATASET-LISTING.COLUMNS.DESCRIPTION' | translate}} - {{row.description}} - + + + {{'DATASET-LISTING.COLUMNS.DESCRIPTION' | translate}} + {{row.description}} + - - - {{'DATASET-LISTING.COLUMNS.CREATED' | translate}} - {{row.created | date:'shortDate'}} - + + + {{'DATASET-LISTING.COLUMNS.CREATED' | translate}} + {{row.created | date:'shortDate'}} + - - - {{'DATASET-LISTING.COLUMNS.ACTIONS' | translate}} - - - - + + + {{'DATASET-LISTING.COLUMNS.ACTIONS' | translate}} + + + + - - - - + + + + - - - + + + - - - - + + + + - -
\ No newline at end of file + + diff --git a/dmp-frontend/src/app/dmps/editor/dmp-editor.component.html b/dmp-frontend/src/app/dmps/editor/dmp-editor.component.html index d707f957b..2dd084e5f 100644 --- a/dmp-frontend/src/app/dmps/editor/dmp-editor.component.html +++ b/dmp-frontend/src/app/dmps/editor/dmp-editor.component.html @@ -4,9 +4,12 @@ + {{'DMP-EDITOR.TITLE.NEW' | translate}} - {{formGroup.get('label').value}} + +

{{formGroup.get('label').value}}

+
-
- - - - - - - {{ option.label }} - - - - - - - - - {{baseErrorModel.label}} @@ -115,6 +101,17 @@ add_circle + +

{{'DMP-EDITOR.FIELDS.PROFILE' | translate}}

+ + + + + + {{ option.label }} + + + diff --git a/dmp-frontend/src/app/dmps/editor/dynamic-fields-project/dynamic-fields-project.component.ts b/dmp-frontend/src/app/dmps/editor/dynamic-fields-project/dynamic-fields-project.component.ts index 4ca3060c9..a42e9f721 100644 --- a/dmp-frontend/src/app/dmps/editor/dynamic-fields-project/dynamic-fields-project.component.ts +++ b/dmp-frontend/src/app/dmps/editor/dynamic-fields-project/dynamic-fields-project.component.ts @@ -14,7 +14,6 @@ export class DynamicFieldsProjectComponent implements OnInit { formGroup: FormGroup; ngOnInit(): void { - console.log(this.formGroup) } findDependencies(id: number) { diff --git a/dmp-frontend/src/app/dmps/listing/dmp-listing.component.html b/dmp-frontend/src/app/dmps/listing/dmp-listing.component.html index 579836e7c..f8d01161c 100644 --- a/dmp-frontend/src/app/dmps/listing/dmp-listing.component.html +++ b/dmp-frontend/src/app/dmps/listing/dmp-listing.component.html @@ -1,5 +1,5 @@
-

{{'DMP-LISTING.TITLE' | translate}}

+

{{'DMP-LISTING.TITLE' | translate}} {{titlePrefix}}

@@ -48,7 +48,9 @@ {{'DMP-LISTING.COLUMNS.DATASETS' | translate}} - {{row.numOfDatasets}} + + {{row.numOfDatasets}} + @@ -78,7 +80,7 @@ -
diff --git a/dmp-frontend/src/app/dmps/listing/dmp-listing.component.ts b/dmp-frontend/src/app/dmps/listing/dmp-listing.component.ts index 7930e654b..4b1a34f69 100644 --- a/dmp-frontend/src/app/dmps/listing/dmp-listing.component.ts +++ b/dmp-frontend/src/app/dmps/listing/dmp-listing.component.ts @@ -35,6 +35,7 @@ export class DataManagementPlanListingComponent implements OnInit { itemId: string; projectId: string; showProject: boolean; + titlePrefix: string; constructor( private dataManagementPlanService: DataManagementPlanService, private router: Router, @@ -64,6 +65,10 @@ export class DataManagementPlanListingComponent implements OnInit { this.refresh(); this.criteria.setRefreshCallback(() => this.refresh()); } + + if (this.projectId != null) + if (params['projectLabel'] != undefined) + this.titlePrefix = "for " + params['projectLabel']; }) } diff --git a/dmp-frontend/src/app/models/datasets/DatasetModel.ts b/dmp-frontend/src/app/models/datasets/DatasetModel.ts index 2a3f2df8a..a1bf300cf 100644 --- a/dmp-frontend/src/app/models/datasets/DatasetModel.ts +++ b/dmp-frontend/src/app/models/datasets/DatasetModel.ts @@ -10,60 +10,60 @@ import { RegisterModel } from "../registers/RegisterModel"; import { DataRepositoryModel } from "../dataRepositories/DataRepositoryModel"; export class DatasetModel implements Serializable { - public id: String; - public label: String; - public profile: String; - public uri: String; - public status: String; - public description: String; - public services: ServiceModel[] = []; - public registries: RegisterModel[] = []; - public dataRepositories: DataRepositoryModel[] = []; + public id: String; + public label: String; + public profile: String; + public uri: String; + public status: String; + public description: String; + public services: ServiceModel[] = []; + public registries: RegisterModel[] = []; + public dataRepositories: DataRepositoryModel[] = []; - public errorModel: BaseErrorModel = new BaseErrorModel(); + public errorModel: BaseErrorModel = new BaseErrorModel(); - fromJSONObject(item: any): DatasetModel { - this.id = item.id; - this.label = item.label; - this.profile = item.profile; - this.uri = item.uri; - this.status = item.status; - this.description = item.description; - this.services = JsonSerializer.fromJSONArray(item.services, ServiceModel); - this.registries = JsonSerializer.fromJSONArray(item.registries, RegisterModel); - this.dataRepositories = JsonSerializer.fromJSONArray(item.dataRepositories, DataRepositoryModel); + fromJSONObject(item: any): DatasetModel { + this.id = item.id; + this.label = item.label; + this.profile = item.profile; + this.uri = item.uri; + this.status = item.status; + this.description = item.description; + this.services = JsonSerializer.fromJSONArray(item.services, ServiceModel); + this.registries = JsonSerializer.fromJSONArray(item.registries, RegisterModel); + this.dataRepositories = JsonSerializer.fromJSONArray(item.dataRepositories, DataRepositoryModel); - return this; - } + return this; + } - buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup { - if (context == null) { context = this.createValidationContext(); } + buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup { + if (context == null) { context = this.createValidationContext(); } - const formGroup = new FormBuilder().group({ - label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators], - profile: [{ value: this.profile, disabled: disabled }, context.getValidation('profile').validators], - uri: [{ value: this.uri, disabled: disabled }, context.getValidation('uri').validators], - status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators], - description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators], - services: [{ value: this.services, disabled: disabled }, context.getValidation('services').validators], - registries: [{ value: this.registries, disabled: disabled }, context.getValidation('registries').validators], - dataRepositories: [{ value: this.dataRepositories, disabled: disabled }, context.getValidation('dataRepositories').validators] - }); + const formGroup = new FormBuilder().group({ + label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators], + profile: [{ value: this.profile, disabled: disabled }, context.getValidation('profile').validators], + uri: [{ value: this.uri, disabled: disabled }, context.getValidation('uri').validators], + status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators], + description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators], + services: [{ value: this.services, disabled: disabled }, context.getValidation('services').validators], + registries: [{ value: this.registries, disabled: disabled }, context.getValidation('registries').validators], + dataRepositories: [{ value: this.dataRepositories, disabled: disabled }, context.getValidation('dataRepositories').validators] + }); - return formGroup; - } + return formGroup; + } - createValidationContext(): ValidationContext { - const baseContext: ValidationContext = new ValidationContext(); - baseContext.validation.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'label')] }); - baseContext.validation.push({ key: 'profile', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'profile')] }); - baseContext.validation.push({ key: 'uri', validators: [BackendErrorValidator(this.errorModel, 'uri')] }); - baseContext.validation.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'status')] }); - baseContext.validation.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'description')] }); - baseContext.validation.push({ key: 'services', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'services')] }); - baseContext.validation.push({ key: 'registries', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'registries')] }); - baseContext.validation.push({ key: 'dataRepositories', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'dataRepositories')] }); + createValidationContext(): ValidationContext { + const baseContext: ValidationContext = new ValidationContext(); + baseContext.validation.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'label')] }); + baseContext.validation.push({ key: 'profile', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'profile')] }); + baseContext.validation.push({ key: 'uri', validators: [BackendErrorValidator(this.errorModel, 'uri')] }); + baseContext.validation.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'status')] }); + baseContext.validation.push({ key: 'description', validators: [BackendErrorValidator(this.errorModel, 'description')] }); + baseContext.validation.push({ key: 'services', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'services')] }); + baseContext.validation.push({ key: 'registries', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'registries')] }); + baseContext.validation.push({ key: 'dataRepositories', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'dataRepositories')] }); - return baseContext; - } -} \ No newline at end of file + return baseContext; + } +} diff --git a/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts b/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts index 1bff68d13..583556572 100644 --- a/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts +++ b/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts @@ -65,7 +65,7 @@ export class DatasetWizardModel implements Serializable { } else { //externalDatasetsFormArray.push(new ExternalDatasetModel().buildForm(context.getValidation('externalDatasets').descendantValidations, disabled)); } - formGroup.addControl('externalDatasets', formBuilder.array(externalDatasetsFormArray, Validators.required)); + formGroup.addControl('externalDatasets', formBuilder.array(externalDatasetsFormArray)); const registriesFormArray = new Array(); if (this.registries && this.registries.length > 0) { @@ -75,7 +75,7 @@ export class DatasetWizardModel implements Serializable { } else { //externalDatasetsFormArray.push(new ExternalDatasetModel().buildForm(context.getValidation('externalDatasets').descendantValidations, disabled)); } - formGroup.addControl('registries', formBuilder.array(registriesFormArray, Validators.required)); + formGroup.addControl('registries', formBuilder.array(registriesFormArray)); const dataRepositoriesFormArray = new Array(); if (this.dataRepositories && this.dataRepositories.length > 0) { @@ -85,7 +85,7 @@ export class DatasetWizardModel implements Serializable { } else { //externalDatasetsFormArray.push(new ExternalDatasetModel().buildForm(context.getValidation('externalDatasets').descendantValidations, disabled)); } - formGroup.addControl('dataRepositories', formBuilder.array(dataRepositoriesFormArray, Validators.required)); + formGroup.addControl('dataRepositories', formBuilder.array(dataRepositoriesFormArray)); const servicesFormArray = new Array(); if (this.services && this.services.length > 0) { @@ -95,7 +95,7 @@ export class DatasetWizardModel implements Serializable { } else { //externalDatasetsFormArray.push(new ExternalDatasetModel().buildForm(context.getValidation('externalDatasets').descendantValidations, disabled)); } - formGroup.addControl('services', formBuilder.array(servicesFormArray, Validators.required)); + formGroup.addControl('services', formBuilder.array(servicesFormArray)); if (this.datasetProfileDefinition) formGroup.addControl("datasetProfileDefinition", this.datasetProfileDefinition.buildForm()) formGroup.addControl("profile", this.profile.buildForm()) @@ -109,7 +109,7 @@ export class DatasetWizardModel implements Serializable { baseContext.validation.push({ key: 'profile', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'profile')] }); baseContext.validation.push({ key: 'uri', validators: [BackendErrorValidator(this.errorModel, 'uri')] }); baseContext.validation.push({ key: 'status', validators: [BackendErrorValidator(this.errorModel, 'status')] }); - baseContext.validation.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'description')] }); + baseContext.validation.push({ key: 'description', validators: [BackendErrorValidator(this.errorModel, 'description')] }); baseContext.validation.push({ key: 'services', validators: [BackendErrorValidator(this.errorModel, 'services')] }); baseContext.validation.push({ key: 'registries', validators: [BackendErrorValidator(this.errorModel, 'registries')] }); baseContext.validation.push({ key: 'dataRepositories', validators: [BackendErrorValidator(this.errorModel, 'dataRepositories')] }); diff --git a/dmp-frontend/src/app/models/projects/ProjectModel.ts b/dmp-frontend/src/app/models/projects/ProjectModel.ts index b2f6eb21d..d4b044d4c 100644 --- a/dmp-frontend/src/app/models/projects/ProjectModel.ts +++ b/dmp-frontend/src/app/models/projects/ProjectModel.ts @@ -17,7 +17,7 @@ export class ProjectModel implements Serializable { public label: String; public abbreviation: String; public reference: String; - public type: ProjectType; + public type: ProjectType = ProjectType.Internal; public uri: String; public status: Status = Status.Active; public startDate: Date; @@ -73,7 +73,7 @@ export class ProjectModel implements Serializable { baseContext.validation.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'description')] }); baseContext.validation.push({ key: 'startDate', validators: [BackendErrorValidator(this.errorModel, 'startDate')] }); baseContext.validation.push({ key: 'endDate', validators: [BackendErrorValidator(this.errorModel, 'endDate')] }); - baseContext.validation.push({ key: 'files', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'files')] }); + baseContext.validation.push({ key: 'files', validators: [BackendErrorValidator(this.errorModel, 'files')] }); return baseContext; } diff --git a/dmp-frontend/src/app/projects/editor/project-editor.component.html b/dmp-frontend/src/app/projects/editor/project-editor.component.html index 1173c0446..683a90490 100644 --- a/dmp-frontend/src/app/projects/editor/project-editor.component.html +++ b/dmp-frontend/src/app/projects/editor/project-editor.component.html @@ -5,17 +5,18 @@ {{'PROJECT-EDITOR.TITLE.NEW' | translate}} {{formGroup.get('label').value}}
- - - - +
+ + + +
@@ -85,7 +86,7 @@
- +
diff --git a/dmp-frontend/src/app/projects/editor/project-editor.component.ts b/dmp-frontend/src/app/projects/editor/project-editor.component.ts index bd51a4580..19e0e3275 100644 --- a/dmp-frontend/src/app/projects/editor/project-editor.component.ts +++ b/dmp-frontend/src/app/projects/editor/project-editor.component.ts @@ -171,7 +171,7 @@ export class ProjectEditorComponent implements AfterViewInit { } public goToProjectDmps() { - this.router.navigate(["dmps/project/" + this.project.id]) + this.router.navigate(["dmps/project/" + this.project.id, { projectLabel: this.project.label }]) } public isExternalProject() { diff --git a/dmp-frontend/src/app/projects/listing/project-listing.component.html b/dmp-frontend/src/app/projects/listing/project-listing.component.html index efe744aab..0a88cc1ad 100644 --- a/dmp-frontend/src/app/projects/listing/project-listing.component.html +++ b/dmp-frontend/src/app/projects/listing/project-listing.component.html @@ -1,69 +1,69 @@
-

{{languageResolverService.getBy('listingTitle') | translate}}

+

{{languageResolverService.getBy('listingTitle') | translate}}

- - - - - + + + + + - + - - {{'PROJECT-LISTING.COLUMNS.AVATAR' | translate}} - - - - - - - {{'PROJECT-LISTING.COLUMNS.NAME' | translate}} - {{row.label}} - + + {{'PROJECT-LISTING.COLUMNS.AVATAR' | translate}} + + + + + + + {{'PROJECT-LISTING.COLUMNS.NAME' | translate}} + {{row.label}} + - - - {{'PROJECT-LISTING.COLUMNS.ABBREVIATION' | translate}} - {{row.abbreviation}} - + + + {{'PROJECT-LISTING.COLUMNS.ABBREVIATION' | translate}} + {{row.abbreviation}} + - - - {{'PROJECT-LISTING.COLUMNS.START' | translate}} - {{row.startDate | date:'shortDate'}} - + + + {{'PROJECT-LISTING.COLUMNS.START' | translate}} + {{row.startDate | date:'shortDate'}} + - - - {{'PROJECT-LISTING.COLUMNS.END' | translate}} - {{row.endDate | date:'shortDate'}} - + + + {{'PROJECT-LISTING.COLUMNS.END' | translate}} + {{row.endDate | date:'shortDate'}} + - - - {{'PROJECT-LISTING.COLUMNS.DMPS' | translate}} - - - - + + + {{'PROJECT-LISTING.COLUMNS.DMPS' | translate}} + + + + - - + - - + + - - - - + + + + - -
\ No newline at end of file + + diff --git a/dmp-frontend/src/app/services/help-content/help-content.service.ts b/dmp-frontend/src/app/services/help-content/help-content.service.ts index f5756d583..f14e70982 100644 --- a/dmp-frontend/src/app/services/help-content/help-content.service.ts +++ b/dmp-frontend/src/app/services/help-content/help-content.service.ts @@ -9,48 +9,47 @@ import { CachedContentItem } from './CachedContentItem'; import { HostConfiguration } from '../../app.constants'; @Injectable() export class HelpContentService { - private _helpServiceUrl = HostConfiguration.HelpServiceUrl; - cache = new Map(); + private _helpServiceUrl = HostConfiguration.HelpServiceUrl; + cache = new Map(); - constructor(private http: Http) { - } + constructor(private http: Http) { + } - getActivePageContent(route: string) { - if (!this.cache.get(route) || !this.isValidCachedItem(route)) { - return this.http.get(this._helpServiceUrl + "/page/route?q=" + route) - .map(res => { - this.cache.set(route, { timestamp: Date.now(), content: res.json() }) - return res.json(); - }) - .catch(this.handleError) - } - return Observable.create(observer => observer.next(this.cache.get(route).content)); + getActivePageContent(route: string) { + if (!this.cache.get(route) || !this.isValidCachedItem(route)) { + return this.http.get(this._helpServiceUrl + "/page/route?q=" + route) + .map(res => { + this.cache.set(route, { timestamp: Date.now(), content: res.json() }) + return res.json(); + }) + .catch(this.handleError) } - private extractData(res: Response) { - let body = res.json(); - return body.data || {}; - } - private handleError(error: Response | any) { - // In a real world app, we might use a remote logging infrastructure - // We'd also dig deeper into the error to get a better message - let errMsg = ""; - console.log(error); - if (error instanceof Response) { - const body = error.text() || ''; - //const err = body.error || JSON.stringify(body); - errMsg = `${error.status} - ${error.statusText || ''} ${body}`; - } else { - errMsg = (error.message) ? error.message : - error.status ? `${error.status} - ${error.statusText}` : 'Server error'; - console.error(errMsg); // log to console instead - } - return Observable.throw(errMsg); + return Observable.create(observer => observer.next(this.cache.get(route).content)); + } + private extractData(res: Response) { + let body = res.json(); + return body.data || {}; + } + private handleError(error: Response | any) { + // In a real world app, we might use a remote logging infrastructure + // We'd also dig deeper into the error to get a better message + let errMsg = ""; + if (error instanceof Response) { + const body = error.text() || ''; + //const err = body.error || JSON.stringify(body); + errMsg = `${error.status} - ${error.statusText || ''} ${body}`; + } else { + errMsg = (error.message) ? error.message : + error.status ? `${error.status} - ${error.statusText}` : 'Server error'; + console.error(errMsg); // log to console instead } + return Observable.throw(errMsg); + } - isValidCachedItem(route) { - let cachedTimestamp = this.cache.get(route).timestamp; - let currentTimestamp = Date.now(); - if (currentTimestamp - cachedTimestamp > HostConfiguration.CacheLifeTimeMillis) return false; - else return true; - } -} \ No newline at end of file + isValidCachedItem(route) { + let cachedTimestamp = this.cache.get(route).timestamp; + let currentTimestamp = Date.now(); + if (currentTimestamp - cachedTimestamp > HostConfiguration.CacheLifeTimeMillis) return false; + else return true; + } +} diff --git a/dmp-frontend/src/app/shared/components/available-profiles/available-profiles.component.ts b/dmp-frontend/src/app/shared/components/available-profiles/available-profiles.component.ts index 2be66061b..4c1fd5d2d 100644 --- a/dmp-frontend/src/app/shared/components/available-profiles/available-profiles.component.ts +++ b/dmp-frontend/src/app/shared/components/available-profiles/available-profiles.component.ts @@ -36,7 +36,6 @@ export class AvailableProfilesComponent implements OnInit { } addProfiles(profiles) { - console.log(profiles) // profiles.selectedOptions.forEach(element => { // selectedProfiles.push(element.value) // }); diff --git a/dmp-frontend/src/app/shared/components/criteria/datamanagementplanprofile/dmp-profile-criteria.component.ts b/dmp-frontend/src/app/shared/components/criteria/datamanagementplanprofile/dmp-profile-criteria.component.ts index 612b0db27..fc8fa0827 100644 --- a/dmp-frontend/src/app/shared/components/criteria/datamanagementplanprofile/dmp-profile-criteria.component.ts +++ b/dmp-frontend/src/app/shared/components/criteria/datamanagementplanprofile/dmp-profile-criteria.component.ts @@ -7,7 +7,6 @@ import { BackendErrorValidator } from '../../../../utilities/validators/BackendE import { DataManagementPlanCriteria } from '../../../../models/criteria/data-management-plan/DataManagementPlanCriteria'; import { DataManagementPlanCriteriaErrorModel } from '../../../../models/criteria/data-management-plan/DataManagementPlanCriteriaErrorModel'; import { ProjectModel } from '../../../../models/projects/ProjectModel'; -import { ProjectService } from '../../../../services/project/project.service'; import { ProjectCriteria } from '../../../../models/criteria/project/ProjectCriteria'; import { RequestItem } from '../../../../models/criteria/RequestItem'; import { create } from 'domain'; @@ -30,8 +29,7 @@ export class DataManagementPlanProfileCriteriaComponent extends BaseCriteriaComp constructor( public language: TranslateService, - public projectService: ProjectService, - public formBuilder: FormBuilder + public formBuilder: FormBuilder ) { super(new DataManagementPlanProfileCriteriaErrorModel()); } diff --git a/dmp-frontend/src/app/shared/components/criteria/users/users-criteria.component.ts b/dmp-frontend/src/app/shared/components/criteria/users/users-criteria.component.ts index 1b7c07b1d..b87e83549 100644 --- a/dmp-frontend/src/app/shared/components/criteria/users/users-criteria.component.ts +++ b/dmp-frontend/src/app/shared/components/criteria/users/users-criteria.component.ts @@ -9,75 +9,74 @@ import { Principal } from '../../../../models/login/Principal'; import { FormBuilder, FormGroup } from '@angular/forms'; @Component({ - selector: 'users-criteria-component', - templateUrl: './users-criteria.component.html', - styleUrls: ['./users-criteria.component.scss'], + selector: 'users-criteria-component', + templateUrl: './users-criteria.component.html', + styleUrls: ['./users-criteria.component.scss'], }) export class UsersCriteriaComponent extends BaseCriteriaComponent implements OnInit { - public role: Principal.AppRole; - public criteria: UserCriteria = new UserCriteria(); + public role: Principal.AppRole; + public criteria: UserCriteria = new UserCriteria(); - constructor( - public language: TranslateService, - public errorModel: UserCriteriaErrorModel, - public formBuilder: FormBuilder - ) { - super(errorModel); - } + constructor( + public language: TranslateService, + public formBuilder: FormBuilder + ) { + super(new UserCriteriaErrorModel()); + } - ngOnInit() { - super.ngOnInit(); - if (this.criteria == null) { this.criteria = new UserCriteria(); } - if (this.formGroup == null) { this.formGroup = this.buildForm(); } - } + ngOnInit() { + super.ngOnInit(); + if (this.criteria == null) { this.criteria = new UserCriteria(); } + if (this.formGroup == null) { this.formGroup = this.buildForm(); } + } - setCriteria(criteria: UserCriteria): void { - this.criteria = criteria; - this.formGroup = this.buildForm(); - } + setCriteria(criteria: UserCriteria): void { + this.criteria = criteria; + this.formGroup = this.buildForm(); + } - public fromJSONObject(item: any): UserCriteria { - this.criteria = new UserCriteria(); - this.criteria.label = item.Label; - this.criteria.appRoles = item.appRoles; - return this.criteria; - } + public fromJSONObject(item: any): UserCriteria { + this.criteria = new UserCriteria(); + this.criteria.label = item.Label; + this.criteria.appRoles = item.appRoles; + return this.criteria; + } - buildForm(): FormGroup { - const context: ValidationContext = this.createValidationContext(); + buildForm(): FormGroup { + const context: ValidationContext = this.createValidationContext(); - return this.formBuilder.group({ - like: [this.criteria.label, context.getValidation('label').validators], - appRoles: [this.criteria.appRoles, context.getValidation('appRoles').validators], - }); - } + return this.formBuilder.group({ + like: [this.criteria.label, context.getValidation('label').validators], + appRoles: [this.criteria.appRoles, context.getValidation('appRoles').validators], + }); + } - createValidationContext(): ValidationContext { - const validationContext: ValidationContext = new ValidationContext(); - const validationArray: Validation[] = new Array(); + createValidationContext(): ValidationContext { + const validationContext: ValidationContext = new ValidationContext(); + const validationArray: Validation[] = new Array(); - validationArray.push({ key: 'label' }); - validationArray.push({ key: 'appRoles' }); + validationArray.push({ key: 'label' }); + validationArray.push({ key: 'appRoles' }); - validationContext.validation = validationArray; - return validationContext; - } + validationContext.validation = validationArray; + return validationContext; + } - getPrincipalAppRoleValues(): Number[] { - let keys: string[] = Object.keys(Principal.AppRole); - keys = keys.slice(0, keys.length / 2); - const values: Number[] = keys.map(Number); - return values; - } + getPrincipalAppRoleValues(): Number[] { + let keys: string[] = Object.keys(Principal.AppRole); + keys = keys.slice(0, keys.length / 2); + const values: Number[] = keys.map(Number); + return values; + } - getPrincipalAppRoleWithLanguage(role: Principal.AppRole): string { - let result = ''; - this.language.get(new Utilities().convertFromPrincipalAppRole(role)).subscribe((value: string) => { - result = value; - }); - return result; - } + getPrincipalAppRoleWithLanguage(role: Principal.AppRole): string { + let result = ''; + this.language.get(new Utilities().convertFromPrincipalAppRole(role)).subscribe((value: string) => { + result = value; + }); + return result; + } } diff --git a/dmp-frontend/src/app/shared/components/external-items/external-item-listing/external-item-listing.component.html b/dmp-frontend/src/app/shared/components/external-items/external-item-listing/external-item-listing.component.html index 651a2966c..be040b9ce 100644 --- a/dmp-frontend/src/app/shared/components/external-items/external-item-listing/external-item-listing.component.html +++ b/dmp-frontend/src/app/shared/components/external-items/external-item-listing/external-item-listing.component.html @@ -12,8 +12,8 @@ [placeholder]="placeholder" (onItemChange)="this.onItemChangeFunc($event)" [formCtrl]="formControl" [disabled]="disabled"> -
- +
+
diff --git a/dmp-frontend/src/app/shared/components/external-items/external-item-listing/external-item-listing.component.ts b/dmp-frontend/src/app/shared/components/external-items/external-item-listing/external-item-listing.component.ts index dd8b8b2cd..9568aaa26 100644 --- a/dmp-frontend/src/app/shared/components/external-items/external-item-listing/external-item-listing.component.ts +++ b/dmp-frontend/src/app/shared/components/external-items/external-item-listing/external-item-listing.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit, Input, ContentChild, TemplateRef, ViewChild, Output, EventEmitter } from "@angular/core"; import { AutoCompleteConfiguration } from "../../autocomplete/AutoCompleteConfiguration"; -import { FormGroup, FormControl } from "@angular/forms"; +import { FormGroup, FormControl, FormArray, AbstractControl } from "@angular/forms"; import { ExternalSourcesUrlModel } from "../../../../models/external-sources/ExternalSourcesUrlModel"; @Component({ @@ -13,7 +13,7 @@ export class ExternalItemListingComponent implements OnInit { public placeholder: string; @Input() - public formGroup: FormGroup; + public formGroup: AbstractControl; @Input() public autoCompleteConfiguration: AutoCompleteConfiguration; @@ -39,6 +39,7 @@ export class ExternalItemListingComponent implements OnInit { public choice: string; public formControl = new FormControl(); + ngOnInit() { if (this.disabled) this.formControl.disable(); } @@ -51,5 +52,9 @@ export class ExternalItemListingComponent implements OnInit { if (this.formControl.disabled) this.formControl.enable(); this.autoCompleteConfiguration.requestItem.criteria["type"] = event.value; } + + deleteItem(name: number) { + (this.formGroup).removeAt(name) + } } diff --git a/dmp-frontend/src/app/shared/components/external-items/external-item/external-item.component.ts b/dmp-frontend/src/app/shared/components/external-items/external-item/external-item.component.ts index 56533df29..c463e8f36 100644 --- a/dmp-frontend/src/app/shared/components/external-items/external-item/external-item.component.ts +++ b/dmp-frontend/src/app/shared/components/external-items/external-item/external-item.component.ts @@ -35,7 +35,6 @@ export class ExternalItemComponent implements OnInit { public formCtrl: FormControl; ngOnInit() { - //this.formCtrl.valueChanges.subscribe(x => console.log(x)); } onItemChangeFunc(event) { diff --git a/dmp-frontend/src/app/shared/components/file-uploader/file-uploader.component.ts b/dmp-frontend/src/app/shared/components/file-uploader/file-uploader.component.ts index 35270e11e..0619c446a 100644 --- a/dmp-frontend/src/app/shared/components/file-uploader/file-uploader.component.ts +++ b/dmp-frontend/src/app/shared/components/file-uploader/file-uploader.component.ts @@ -3,55 +3,54 @@ import { FileUploader } from "../../../shared/components/file-uploader/FileUploa import { FormControl } from "@angular/forms"; @Component({ - selector: 'app-fileuploader-component', - templateUrl: './file-uploader.component.html' + selector: 'app-fileuploader-component', + templateUrl: './file-uploader.component.html' }) export class FileUploaderComponent implements OnInit { - files: File | FileList; - disabled: boolean = false; + files: File | FileList; + disabled: boolean = false; - fileSelectMultipleMsg: string = 'No file(s) selected yet.'; + fileSelectMultipleMsg: string = 'No file(s) selected yet.'; - @Input() - public label: string = 'FILE-UPLOADER.DEFAULT'; + @Input() + public label: string = 'FILE-UPLOADER.DEFAULT'; - @Input() - public fileUploader: FileUploader; + @Input() + public fileUploader: FileUploader; - @Input() - form: FormControl; + @Input() + form: FormControl; - ngOnInit(): void { - console.log(this.form) + ngOnInit(): void { + } + + selectEvent(files: FileList | File): void { + this.label = 'FILE-UPLOADER.UPLOAD' + if (files instanceof FileList) { + let names: string[] = []; + for (let i: number = 0; i < files.length; i++) { + names.push(files[i].name); + } + this.fileSelectMultipleMsg = names.join(','); + } else { + this.fileSelectMultipleMsg = files.name; } + } - selectEvent(files: FileList | File): void { - this.label = 'FILE-UPLOADER.UPLOAD' - if (files instanceof FileList) { - let names: string[] = []; - for (let i: number = 0; i < files.length; i++) { - names.push(files[i].name); - } - this.fileSelectMultipleMsg = names.join(','); - } else { - this.fileSelectMultipleMsg = files.name; - } + uploadEvent(files: FileList | File): void { + let formdata: FormData = new FormData(); + + if (files instanceof FileList) { + for (let i: number = 0; i < files.length; i++) { + formdata.append('file', files[i]); + } + } else { + formdata.append('file', files); } + this.fileUploader.uploadFile(formdata).subscribe(files => this.form.patchValue(files)); + } - uploadEvent(files: FileList | File): void { - let formdata: FormData = new FormData(); - - if (files instanceof FileList) { - for (let i: number = 0; i < files.length; i++) { - formdata.append('file', files[i]); - } - } else { - formdata.append('file', files); - } - this.fileUploader.uploadFile(formdata).subscribe(files => this.form.patchValue(files)); - } - - cancelEvent(): void { - } -} \ No newline at end of file + cancelEvent(): void { + } +} diff --git a/dmp-frontend/src/app/shared/components/url-listing/url-listing.component.ts b/dmp-frontend/src/app/shared/components/url-listing/url-listing.component.ts index 40b3dcb3d..2dacfc038 100644 --- a/dmp-frontend/src/app/shared/components/url-listing/url-listing.component.ts +++ b/dmp-frontend/src/app/shared/components/url-listing/url-listing.component.ts @@ -1,27 +1,30 @@ import { Component, Input } from "@angular/core"; import { UrlListingItem } from "../../../shared/components/url-listing/UrlListingItem"; import { Router } from "@angular/router"; +import { UrlUtilities } from "../../../utilities/UrlUtilities"; @Component({ - selector: 'app-url-listing', - templateUrl: './url-listing.component.html' + selector: 'app-url-listing', + templateUrl: './url-listing.component.html' }) export class UrlListingComponent { - @Input() - items: UrlListingItem[]; + @Input() + items: UrlListingItem[]; - @Input() - urlLimit: number = 3; + @Input() + parameters: any - constructor(private router: Router) { } + @Input() + urlLimit: number = 3; - ngOnInit() { + constructor(private router: Router, private urlUtilities: UrlUtilities) { } - console.log(this.items.length > this.urlLimit) - } + ngOnInit() { - navigate(link: string) { - this.router.navigateByUrl(link); - } -} \ No newline at end of file + } + + navigate(link: string) { + this.router.navigate([link, this.parameters]); + } +} diff --git a/dmp-frontend/src/app/shared/guards/auth.guard.ts b/dmp-frontend/src/app/shared/guards/auth.guard.ts index ee7ed6f75..1988fd26e 100644 --- a/dmp-frontend/src/app/shared/guards/auth.guard.ts +++ b/dmp-frontend/src/app/shared/guards/auth.guard.ts @@ -6,7 +6,6 @@ import { AuthService } from '../../services/auth/auth.service'; export class AuthGuard implements CanActivate { constructor(private auth: AuthService, private router: Router) { - console.log(auth); } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { let url: string = state.url; diff --git a/dmp-frontend/src/app/users/components/roles/user-role-editor.component.ts b/dmp-frontend/src/app/users/components/roles/user-role-editor.component.ts index e5a51c60b..f1fcbaf5e 100644 --- a/dmp-frontend/src/app/users/components/roles/user-role-editor.component.ts +++ b/dmp-frontend/src/app/users/components/roles/user-role-editor.component.ts @@ -21,11 +21,10 @@ export class UserRoleEditorComponent implements OnInit { @Input() public item: UserListingModel; private formGroup: FormGroup = null; private nowEditing = false; - + private errorModel: UserErrorModel; constructor( private language: TranslateService, private userService: UserReferenceService, - private errorModel: UserErrorModel, private formBuilder: FormBuilder, private snackBar: MatSnackBar ) { diff --git a/dmp-frontend/src/app/utilities/UrlUtilities.ts b/dmp-frontend/src/app/utilities/UrlUtilities.ts new file mode 100644 index 000000000..3ae4a39c5 --- /dev/null +++ b/dmp-frontend/src/app/utilities/UrlUtilities.ts @@ -0,0 +1,17 @@ +import { Injectable } from "@angular/core"; + +@Injectable() +export class UrlUtilities { + + public applyUrlTemplate(url: string, params: any): string { + let paramsToString = ""; + if (params) paramsToString = "?" + let keys = Object.keys(params); + keys.forEach(x => { + if (keys.indexOf(x) > 0) paramsToString += "&" + paramsToString += x + "=" + params[x]; + }) + return url + paramsToString; + } + +} diff --git a/dmp-frontend/src/environments/environment.prod.ts b/dmp-frontend/src/environments/environment.prod.ts index 1b3edd88f..664479b7d 100644 --- a/dmp-frontend/src/environments/environment.prod.ts +++ b/dmp-frontend/src/environments/environment.prod.ts @@ -1,6 +1,6 @@ export const environment = { production: true, - Server: 'http://dl043.madgik.di.uoa.gr:8080/api/', - App: 'http://dl043.madgik.di.uoa.gr:8080/', + Server: 'http://dl043.madgik.di.uoa.gr/api/', + App: 'http://dl043.madgik.di.uoa.gr/', HelpServiceUrl: 'http://dl043.madgik.di.uoa.gr:5555/' };