Merge branch 'Development' of https://code-repo.d4science.org/MaDgiK-CITE/argos into Development
This commit is contained in:
commit
bf77a85acb
|
@ -15,6 +15,7 @@ import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
|||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl;
|
||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||
import eu.eudat.logic.utilities.documents.pdf.PDFUtils;
|
||||
import eu.eudat.models.data.dataset.DatasetOverviewModel;
|
||||
|
@ -126,11 +127,11 @@ public class Datasets extends BaseController {
|
|||
public @ResponseBody
|
||||
ResponseEntity getSingle(@PathVariable String id, @RequestHeader("Content-Type") String contentType, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException {
|
||||
try {
|
||||
VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl();
|
||||
if (contentType.equals("application/xml")) {
|
||||
VisibilityRuleService visibilityRuleService = this.getApiContext().getUtilitiesService().getVisibilityRuleService();
|
||||
return this.datasetManager.getDocument(id, visibilityRuleService, contentType, principal);
|
||||
} else if (contentType.equals("application/msword")) {
|
||||
FileEnvelope file = datasetManager.getWordDocumentFile(this.configLoader, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService(), principal);
|
||||
FileEnvelope file = datasetManager.getWordDocumentFile(this.configLoader, id, visibilityRuleService, principal);
|
||||
InputStream resource = new FileInputStream(file.getFile());
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.setContentLength(file.getFile().length());
|
||||
|
@ -218,7 +219,7 @@ public class Datasets extends BaseController {
|
|||
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
||||
FileEnvelope file = datasetManager.getWordDocumentFile(this.configLoader, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService(), principal);
|
||||
FileEnvelope file = datasetManager.getWordDocumentFile(this.configLoader, id, new VisibilityRuleServiceImpl(), principal);
|
||||
String fileName = file.getFilename().replace(" ", "_").replace(",", "_");
|
||||
if (fileName.endsWith(".docx")){
|
||||
fileName = fileName.substring(0, fileName.length() - 5);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package eu.eudat.logic.managers;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration;
|
||||
import eu.eudat.configurations.dynamicgrant.entities.Property;
|
||||
|
@ -33,6 +31,7 @@ import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper;
|
|||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl;
|
||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.eudat.logic.services.utilities.UtilitiesService;
|
||||
import eu.eudat.logic.utilities.builders.XmlBuilder;
|
||||
|
@ -106,7 +105,6 @@ public class DataManagementPlanManager {
|
|||
|
||||
private ApiContext apiContext;
|
||||
private DatasetManager datasetManager;
|
||||
private UtilitiesService utilitiesService;
|
||||
private DatabaseRepository databaseRepository;
|
||||
private Environment environment;
|
||||
private RDAManager rdaManager;
|
||||
|
@ -117,7 +115,6 @@ public class DataManagementPlanManager {
|
|||
public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, Environment environment, RDAManager rdaManager, UserManager userManager, MetricsManager metricsManager) {
|
||||
this.apiContext = apiContext;
|
||||
this.datasetManager = datasetManager;
|
||||
this.utilitiesService = apiContext.getUtilitiesService();
|
||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||
this.environment = environment;
|
||||
this.rdaManager = rdaManager;
|
||||
|
@ -1172,7 +1169,7 @@ public class DataManagementPlanManager {
|
|||
|
||||
public FileEnvelope getWordDocument(String id, Principal principal, ConfigLoader configLoader, Boolean versioned) throws IOException {
|
||||
WordBuilder wordBuilder = new WordBuilder();
|
||||
VisibilityRuleService visibilityRuleService = this.utilitiesService.getVisibilityRuleService();
|
||||
VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl();
|
||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||
XWPFDocument document = configLoader.getDocument();
|
||||
|
||||
|
@ -1341,7 +1338,7 @@ public class DataManagementPlanManager {
|
|||
|
||||
private FileEnvelope getXmlDocument(String id, Principal principal) throws InstantiationException, IllegalAccessException, IOException {
|
||||
ExportXmlBuilder xmlBuilder = new ExportXmlBuilder();
|
||||
VisibilityRuleService visibilityRuleService = utilitiesService.getVisibilityRuleService();
|
||||
VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl();
|
||||
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
||||
if (!dmp.isPublic() && dmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
|
||||
throw new UnauthorisedException();
|
||||
|
|
|
@ -26,6 +26,7 @@ import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper;
|
|||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl;
|
||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||
import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
|
||||
|
@ -49,7 +50,6 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
|||
import eu.eudat.queryable.QueryableList;
|
||||
import eu.eudat.types.Authorities;
|
||||
import eu.eudat.types.MetricNames;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
|
@ -60,11 +60,11 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
@ -91,8 +91,6 @@ import java.time.temporal.ChronoUnit;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@Component
|
||||
public class DatasetManager {
|
||||
|
@ -527,7 +525,7 @@ public class DatasetManager {
|
|||
public String getWordDocumentText (Dataset datasetEntity) throws Exception {
|
||||
DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(datasetEntity);
|
||||
datasetWizardModel.setDatasetProfileDefinition(this.getPagedProfile(datasetWizardModel, datasetEntity));
|
||||
XWPFDocument document = getLightWordDocument(this.configLoader, datasetWizardModel, this.apiContext.getUtilitiesService().getVisibilityRuleService());
|
||||
XWPFDocument document = getLightWordDocument(this.configLoader, datasetWizardModel, new VisibilityRuleServiceImpl());
|
||||
XWPFWordExtractor extractor = new XWPFWordExtractor(document);
|
||||
return extractor.getText();/*.replaceAll("\n\\s*", " ");*/
|
||||
}
|
||||
|
@ -657,7 +655,7 @@ public class DatasetManager {
|
|||
|
||||
|
||||
JSONObject obj = new JSONObject(dataset.getProperties());
|
||||
VisibilityRuleService visibilityRuleService = this.apiContext.getUtilitiesService().getVisibilityRuleService();
|
||||
VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl();
|
||||
visibilityRuleService.setProperties(obj.toMap());
|
||||
|
||||
dataset.setProfile(profile);
|
||||
|
@ -666,12 +664,16 @@ public class DatasetManager {
|
|||
|
||||
|
||||
for (String validator : datasetProfileValidators) {
|
||||
if ((obj.has(validator) && (obj.getString(validator) == null || obj.getString(validator).trim().isEmpty())) && isElementVisible(nodeList, validator, visibilityRuleService)) {
|
||||
if (obj.has(validator) && isNullOrEmpty(obj.getString(validator)) && isElementVisible(nodeList, validator, visibilityRuleService)) {
|
||||
throw new Exception("Field value of " + validator + " must be filled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNullOrEmpty(String value) {
|
||||
return value == null || value.trim().isEmpty();
|
||||
}
|
||||
|
||||
private boolean isElementVisible(NodeList nodeList, String id, VisibilityRuleService visibilityRuleService) {
|
||||
Element fieldSet = null;
|
||||
for (int i = 0; i < nodeList.getLength(); i++) {
|
||||
|
|
|
@ -1,30 +1,26 @@
|
|||
package eu.eudat.logic.services.forms;
|
||||
|
||||
import eu.eudat.models.data.user.components.commons.Rule;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/5/2018.
|
||||
*/
|
||||
@Service("visibilityRuleService")
|
||||
public class VisibilityRuleServiceImpl implements VisibilityRuleService {
|
||||
private Map<String, Boolean> elementVisibility = new HashMap<>();
|
||||
private VisibilityContext visibilityContext;
|
||||
private final Map<String, Boolean> elementVisibility = new HashMap<>();
|
||||
private Map<String, Object> properties;
|
||||
|
||||
public boolean isElementVisible(String id) {
|
||||
if (!this.elementVisibility.containsKey(id) || this.elementVisibility.get(id)) return true;
|
||||
return false;
|
||||
return !this.elementVisibility.containsKey(id) || this.elementVisibility.get(id);
|
||||
}
|
||||
|
||||
public void setProperties(Map<String, Object> properties) {
|
||||
this.properties = properties;
|
||||
this.properties.entrySet().stream()
|
||||
.filter(stringObjectEntry -> stringObjectEntry.getValue() instanceof String && ((String) stringObjectEntry.getValue()).startsWith("[") && ((String) stringObjectEntry.getValue()).endsWith("]")).forEach(stringObjectEntry -> {
|
||||
stringObjectEntry.setValue(parseArray((String) stringObjectEntry.getValue()));
|
||||
});
|
||||
.filter(stringObjectEntry -> stringObjectEntry.getValue() instanceof String && ((String) stringObjectEntry.getValue()).startsWith("[")
|
||||
&& ((String) stringObjectEntry.getValue()).endsWith("]"))
|
||||
.forEach(stringObjectEntry -> stringObjectEntry.setValue(parseArray((String) stringObjectEntry.getValue())));
|
||||
}
|
||||
|
||||
private List<String> parseArray(String original) {
|
||||
|
@ -33,22 +29,20 @@ public class VisibilityRuleServiceImpl implements VisibilityRuleService {
|
|||
}
|
||||
|
||||
public void buildVisibilityContext(List<Rule> sources) {
|
||||
this.visibilityContext = new VisibilityContext();
|
||||
this.visibilityContext.buildVisibilityContext(sources);
|
||||
this.visibilityContext.getVisibilityRules().forEach(item-> this.evaluateVisibility(item));
|
||||
VisibilityContext visibilityContext = new VisibilityContext();
|
||||
visibilityContext.buildVisibilityContext(sources);
|
||||
visibilityContext.getVisibilityRules().forEach(this::evaluateVisibility);
|
||||
}
|
||||
|
||||
private void evaluateVisibility(VisibilityRule rule) {
|
||||
List<VisibilityRuleSource> sources = rule.getVisibilityRuleSources();
|
||||
for(int i = 0; i < sources.size(); i++){
|
||||
if (properties.containsKey(sources.get(i).getVisibilityRuleSourceId()) && (isContained(properties.get(sources.get(i).getVisibilityRuleSourceId()), sources.get(i).getVisibilityRuleSourceValue()) || properties.get(sources.get(i).getVisibilityRuleSourceId()).equals(sources.get(i).getVisibilityRuleSourceValue()))) {
|
||||
for(VisibilityRuleSource source: sources){
|
||||
if (properties.containsKey(source.getVisibilityRuleSourceId())
|
||||
&& isContained(properties.get(source.getVisibilityRuleSourceId()), source.getVisibilityRuleSourceValue())) {
|
||||
this.elementVisibility.put(rule.getVisibilityRuleTargetId(), true);
|
||||
} else {
|
||||
if (this.elementVisibility.containsKey(rule.getVisibilityRuleTargetId())) {
|
||||
this.elementVisibility.put(rule.getVisibilityRuleTargetId(), this.elementVisibility.get(rule.getVisibilityRuleTargetId()) || false);
|
||||
} else {
|
||||
this.elementVisibility.put(rule.getVisibilityRuleTargetId(), false);
|
||||
}
|
||||
this.elementVisibility.put(rule.getVisibilityRuleTargetId(),
|
||||
this.elementVisibility.getOrDefault(rule.getVisibilityRuleTargetId(), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +50,8 @@ public class VisibilityRuleServiceImpl implements VisibilityRuleService {
|
|||
private Boolean isContained(Object values, String source) {
|
||||
if (values instanceof List) {
|
||||
return ((Collection<?>) values).contains(source);
|
||||
} else {
|
||||
return values.equals(source);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,5 @@ public interface UtilitiesService {
|
|||
|
||||
MailService getMailService();
|
||||
|
||||
VisibilityRuleService getVisibilityRuleService();
|
||||
|
||||
ConfirmationEmailService getConfirmationEmailService();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.logic.services.utilities;
|
||||
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -12,22 +13,15 @@ public class UtilitiesServiceImpl implements UtilitiesService {
|
|||
|
||||
private InvitationService invitationService;
|
||||
private MailService mailService;
|
||||
private VisibilityRuleService visibilityRuleService;
|
||||
private ConfirmationEmailService confirmationEmailService;
|
||||
|
||||
@Autowired
|
||||
public UtilitiesServiceImpl(InvitationService invitationService, MailService mailService, VisibilityRuleService visibilityRuleService, ConfirmationEmailService confirmationEmailService) {
|
||||
public UtilitiesServiceImpl(InvitationService invitationService, MailService mailService, ConfirmationEmailService confirmationEmailService) {
|
||||
this.invitationService = invitationService;
|
||||
this.mailService = mailService;
|
||||
this.visibilityRuleService = visibilityRuleService;
|
||||
this.confirmationEmailService = confirmationEmailService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityRuleService getVisibilityRuleService() {
|
||||
return visibilityRuleService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfirmationEmailService getConfirmationEmailService() {
|
||||
return confirmationEmailService;
|
||||
|
|
|
@ -27,7 +27,9 @@ import java.io.IOException;
|
|||
import java.math.BigInteger;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
|
@ -397,7 +399,7 @@ public class WordBuilder {
|
|||
try {
|
||||
instant = Instant.parse((String) field.getValue());
|
||||
} catch (DateTimeParseException ex) {
|
||||
instant = Instant.from(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).parse((String) field.getValue()));
|
||||
instant = LocalDate.parse((String) field.getValue()).atStartOfDay().toInstant(ZoneOffset.UTC);
|
||||
}
|
||||
return field.getValue() != null ? DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(instant) : "";
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
//}
|
||||
|
||||
.editor-wrapper {
|
||||
position: relative;
|
||||
border: 1px solid transparent !important;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
@ -40,6 +41,14 @@
|
|||
border: 1px solid #f44336 !important;
|
||||
}
|
||||
|
||||
.clear {
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
bottom: 5px;
|
||||
transform: translate(-50%, -50%);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {Component, Input} from "@angular/core";
|
||||
import {AngularEditorConfig} from "@kolkov/angular-editor";
|
||||
import {FormControl} from "@angular/forms";
|
||||
|
||||
@Component({
|
||||
selector: 'rich-text-editor-component',
|
||||
|
@ -7,6 +8,7 @@ import {AngularEditorConfig} from "@kolkov/angular-editor";
|
|||
<div class="editor-wrapper" [class]="wrapperClasses" [formGroup]="parentFormGroup">
|
||||
<angular-editor class="full-width editor" [id]="id" [config]="editorConfig" [formControlName]="controlName"
|
||||
placeholder="{{(placeholder? (placeholder | translate) : '') + (required ? ' *': '')}}"></angular-editor>
|
||||
<mat-icon *ngIf="formInput.value" (click)="formInput.patchValue('')" class="clear">close</mat-icon>
|
||||
</div>
|
||||
`,
|
||||
styleUrls: ['./rich-text-editor.component.scss']
|
||||
|
@ -53,6 +55,7 @@ export class RichTextEditorComponent {
|
|||
]
|
||||
};
|
||||
|
||||
constructor() {
|
||||
get formInput(): FormControl {
|
||||
return this.parentFormGroup.get(this.controlName);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue