Introduce copy field for stakeholder and align all methods to appy the right structure.
This commit is contained in:
parent
54f9ebb9ce
commit
86f4990d70
|
@ -41,6 +41,9 @@ public class CategoryController {
|
|||
log.debug("Alias: " + categoryFull.getAlias() + " - Id: " + categoryFull.getId() + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId);
|
||||
Stakeholder stakeholder = stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = topicService.findByPath(stakeholder, topicId);
|
||||
if(categoryFull.getId() != null) {
|
||||
this.categoryService.findByPath(topic, categoryFull.getId());
|
||||
}
|
||||
return this.categoryService.save(stakeholder, topic, new Category(categoryFull));
|
||||
}
|
||||
|
||||
|
@ -53,7 +56,7 @@ public class CategoryController {
|
|||
@RequestParam(required = false) String children) {
|
||||
log.debug("delete category");
|
||||
log.debug("Id: " + categoryId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId);
|
||||
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
this.categoryService.delete(stakeholder.getType(), category, true);
|
||||
|
@ -80,7 +83,7 @@ public class CategoryController {
|
|||
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false") Boolean propagate) {
|
||||
log.debug("change category visibility: " + visibility + " - toggle propagate: " + propagate);
|
||||
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
|
||||
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
return this.categoryService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), category, visibility, propagate);
|
||||
|
|
|
@ -70,6 +70,9 @@ public class IndicatorController {
|
|||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
||||
Section section = this.sectionService.findByPath(subCategory, sectionId);
|
||||
if(indicator.getId() != null) {
|
||||
this.indicatorService.findByPath(section, indicator.getId());
|
||||
}
|
||||
return this.indicatorService.save(stakeholder, section, indicator);
|
||||
}
|
||||
|
||||
|
@ -84,7 +87,7 @@ public class IndicatorController {
|
|||
@RequestParam(required = false) String children) {
|
||||
log.debug("delete indicator");
|
||||
log.debug("Id: " + indicatorId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId);
|
||||
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
||||
|
@ -104,7 +107,7 @@ public class IndicatorController {
|
|||
@PathVariable("sectionId") String sectionId,
|
||||
@RequestBody List<String> indicators) {
|
||||
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId);
|
||||
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
||||
|
@ -123,7 +126,7 @@ public class IndicatorController {
|
|||
@RequestParam("visibility") Visibility visibility) {
|
||||
log.debug("change indicator visibility: " + visibility);
|
||||
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId + " - Indicator: " + indicatorId);
|
||||
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
||||
|
|
|
@ -49,6 +49,9 @@ public class SectionController {
|
|||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
||||
if(sectionFull.getId() != null) {
|
||||
this.sectionService.findByPath(subCategory, sectionFull.getId());
|
||||
}
|
||||
return this.sectionService.save(stakeholder, subCategory, new Section(sectionFull), Integer.parseInt(index));
|
||||
}
|
||||
|
||||
|
@ -62,7 +65,7 @@ public class SectionController {
|
|||
@RequestParam(required = false) String children) {
|
||||
log.debug("delete section");
|
||||
log.debug("Id: " + sectionId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
|
||||
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
||||
|
@ -80,7 +83,7 @@ public class SectionController {
|
|||
@RequestBody MoveIndicator moveIndicator) {
|
||||
log.debug("move indicator");
|
||||
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
|
||||
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
||||
|
|
|
@ -3,16 +3,15 @@ package eu.dnetlib.uoamonitorservice.controllers;
|
|||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||
import eu.dnetlib.uoamonitorservice.dto.copy;
|
||||
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
||||
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
|
||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
|
||||
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
|
||||
import eu.dnetlib.uoamonitorservice.service.TopicService;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -45,9 +44,10 @@ public class StakeholderController {
|
|||
|
||||
@PreAuthorize("hasAnyAuthority(" +
|
||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||
"@AuthorizationService.curator(#stakeholder.getType()))")
|
||||
"@AuthorizationService.curator(#copy.stakeholder.getType()))")
|
||||
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
|
||||
public StakeholderFull buildStakeholder(@RequestBody StakeholderFull stakeholder) {
|
||||
public Stakeholder buildStakeholder(@RequestBody copy copy) {
|
||||
Stakeholder stakeholder = copy.getStakeholder();
|
||||
log.debug("build stakeholder");
|
||||
log.debug("Alias: " + stakeholder.getAlias());
|
||||
Portal portal = portalService.getPortal(stakeholder.getAlias());
|
||||
|
@ -58,7 +58,7 @@ public class StakeholderController {
|
|||
portal.setType(stakeholder.getType());
|
||||
portalService.insertPortal(portal);
|
||||
}
|
||||
return this.stakeholderService.buildStakeholder(stakeholder);
|
||||
return this.stakeholderService.buildStakeholder(stakeholder, copy.getCopyId());
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)")
|
||||
|
@ -69,10 +69,8 @@ public class StakeholderController {
|
|||
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@RequestMapping(value = "/stakeholder/default", method = RequestMethod.GET)
|
||||
public List<StakeholderFull> getAllDefaultStakeholders(@RequestParam(required = false) String type) {
|
||||
return this.stakeholderService.getAllDefaultByRole(type).stream()
|
||||
.map(this.stakeholderService::getFullStakeholder)
|
||||
.collect(Collectors.toList());
|
||||
public List<Stakeholder> getAllDefaultStakeholders(@RequestParam(required = false) String type) {
|
||||
return this.stakeholderService.getAllDefaultByRole(type);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/stakeholder", method = RequestMethod.GET)
|
||||
|
@ -102,7 +100,19 @@ public class StakeholderController {
|
|||
+ "@AuthorizationService.manager(#stakeholder.getType(), #stakeholder.getAlias()) "
|
||||
+ ")")
|
||||
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
||||
public StakeholderFull saveStakeholder(@RequestBody StakeholderFull stakeholder) {
|
||||
public Stakeholder saveStakeholder(@RequestBody Stakeholder stakeholder) {
|
||||
log.debug("save stakeholder");
|
||||
log.debug("Alias: " + stakeholder.getAlias() + " - Id: " + stakeholder.getId());
|
||||
return this.stakeholderService.save(stakeholder);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority("
|
||||
+ "@AuthorizationService.PORTAL_ADMIN, "
|
||||
+ "@AuthorizationService.curator(#stakeholder.getType()), "
|
||||
+ "@AuthorizationService.manager(#stakeholder.getType(), #stakeholder.getAlias()) "
|
||||
+ ")")
|
||||
@RequestMapping(value = "/save/full", method = RequestMethod.POST)
|
||||
public StakeholderFull saveStakeholderFull(@RequestBody StakeholderFull stakeholder) {
|
||||
log.debug("save stakeholder");
|
||||
log.debug("Alias: " + stakeholder.getAlias() + " - Id: " + stakeholder.getId());
|
||||
return this.stakeholderService.getFullStakeholder(this.stakeholderService.save(new Stakeholder(stakeholder)));
|
||||
|
@ -123,7 +133,7 @@ public class StakeholderController {
|
|||
@PreAuthorize("isAuthenticated()")
|
||||
@RequestMapping(value = "/{stakeholderId}/change-visibility", method = RequestMethod.POST)
|
||||
public StakeholderFull changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId,
|
||||
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false") Boolean propagate) {
|
||||
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false") Boolean propagate) {
|
||||
log.debug("change stakeholder visibility: " + visibility + " - toggle propagate: " + propagate);
|
||||
log.debug("Stakeholder: " + stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
|
|
|
@ -47,6 +47,9 @@ public class SubCategoryController {
|
|||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
if(subcategoryFull.getId() != null) {
|
||||
this.subCategoryService.findByPath(category, subcategoryFull.getId());
|
||||
}
|
||||
return this.subCategoryService.save(stakeholder, category, new SubCategory(subcategoryFull));
|
||||
}
|
||||
|
||||
|
@ -59,7 +62,7 @@ public class SubCategoryController {
|
|||
@RequestParam(required = false) String children) {
|
||||
log.debug("delete subcategory");
|
||||
log.debug("Id: " + subcategoryId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
|
||||
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
||||
|
@ -91,7 +94,7 @@ public class SubCategoryController {
|
|||
@RequestParam(defaultValue = "false") Boolean propagate) {
|
||||
log.debug("change subCategory visibility: " + visibility + " - toggle propagate: " + propagate);
|
||||
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
|
||||
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
Category category = this.categoryService.findByPath(topic, categoryId);
|
||||
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
|
||||
|
|
|
@ -34,6 +34,9 @@ public class TopicController {
|
|||
log.debug("save topic");
|
||||
log.debug("Alias: " + topicFull.getAlias() + " - Id: " + topicFull.getId() + " - Stakeholder: " + stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
if(topicFull.getId() != null) {
|
||||
this.topicService.findByPath(stakeholder, topicFull.getId());
|
||||
}
|
||||
return this.topicService.save(stakeholder, new Topic(topicFull));
|
||||
}
|
||||
|
||||
|
@ -44,7 +47,7 @@ public class TopicController {
|
|||
@RequestParam(required = false) String children) {
|
||||
log.debug("delete topic");
|
||||
log.debug("Id: " + topicId + " - Stakeholder: " + stakeholderId);
|
||||
Stakeholder stakeholder = stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
this.topicService.delete(stakeholder.getType(), topic, true);
|
||||
return true;
|
||||
|
@ -68,7 +71,7 @@ public class TopicController {
|
|||
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false") Boolean propagate) {
|
||||
log.debug("change topic visibility: " + visibility + " - toggle propagate: " + propagate);
|
||||
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId);
|
||||
Stakeholder stakeholder = this.stakeholderService.find(stakeholderId);
|
||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||
Topic topic = this.topicService.findByPath(stakeholder, topicId);
|
||||
return this.topicService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), topic, visibility, propagate);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package eu.dnetlib.uoamonitorservice.dto;
|
||||
|
||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||
|
||||
public class copy {
|
||||
private Stakeholder stakeholder;
|
||||
private String copyId;
|
||||
|
||||
public copy() {
|
||||
}
|
||||
|
||||
public Stakeholder getStakeholder() {
|
||||
return stakeholder;
|
||||
}
|
||||
|
||||
public void setStakeholder(Stakeholder stakeholder) {
|
||||
this.stakeholder = stakeholder;
|
||||
}
|
||||
|
||||
public String getCopyId() {
|
||||
return copyId;
|
||||
}
|
||||
|
||||
public void setCopyId(String copyId) {
|
||||
this.copyId = copyId;
|
||||
}
|
||||
}
|
|
@ -1,16 +1,10 @@
|
|||
package eu.dnetlib.uoamonitorservice.entities;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import eu.dnetlib.uoamonitorservice.generics.Common;
|
||||
import eu.dnetlib.uoamonitorservice.primitives.IndicatorPath;
|
||||
import eu.dnetlib.uoamonitorservice.primitives.IndicatorSize;
|
||||
import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
|
||||
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Indicator extends Common {
|
||||
|
@ -83,8 +77,7 @@ public class Indicator extends Common {
|
|||
if(type == null) {
|
||||
this.type = null;
|
||||
} else {
|
||||
IndicatorType indicatorType = IndicatorType.valueOf(type);
|
||||
this.type = indicatorType;
|
||||
this.type = IndicatorType.valueOf(type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
|||
protected boolean isUpload = false;
|
||||
protected Locale locale = Locale.EU;
|
||||
protected String funderType;
|
||||
protected Boolean copy;
|
||||
protected List<StringOrTopic> topics;
|
||||
|
||||
public StakeholderGeneric() {
|
||||
|
@ -45,6 +46,7 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
|||
setLocale(stakeholder.getLocale());
|
||||
setVisibility(stakeholder.getVisibility());
|
||||
this.funderType = stakeholder.getFunderType();
|
||||
this.copy = stakeholder.isCopy();
|
||||
creationDate = stakeholder.getCreationDate();
|
||||
updateDate = stakeholder.getUpdateDate();
|
||||
}
|
||||
|
@ -60,8 +62,7 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
|||
if (type == null) {
|
||||
this.type = null;
|
||||
} else {
|
||||
StakeholderType stakeholderType = StakeholderType.valueOf(type);
|
||||
this.type = stakeholderType;
|
||||
this.type = StakeholderType.valueOf(type);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,6 +144,17 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
|||
this.funderType = funderType;
|
||||
}
|
||||
|
||||
public boolean isCopy() {
|
||||
if(copy == null) {
|
||||
copy = this.defaultId != null;
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void setCopy(boolean copy) {
|
||||
this.copy = copy;
|
||||
}
|
||||
|
||||
public List<StringOrTopic> getTopics() {
|
||||
return topics;
|
||||
}
|
||||
|
|
|
@ -42,8 +42,7 @@ public class IndicatorPath {
|
|||
if(type == null) {
|
||||
this.type = null;
|
||||
} else {
|
||||
IndicatorPathType indicatorPathType = IndicatorPathType.valueOf(type);
|
||||
this.type = indicatorPathType;
|
||||
this.type = IndicatorPathType.valueOf(type);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,8 +57,7 @@ public class IndicatorPath {
|
|||
if(format == null) {
|
||||
this.format = null;
|
||||
} else {
|
||||
Format _format = Format.valueOf(format);
|
||||
this.format = _format;
|
||||
this.format = Format.valueOf(format);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,11 +64,20 @@ public class CategoryService {
|
|||
return this.getFullCategory(type, alias, category);
|
||||
}
|
||||
|
||||
public String build(String id) {
|
||||
Category category = this.find(id);
|
||||
Category copy = category.copy();
|
||||
copy.setSubCategories(category.getSubCategories().stream().map(this.subCategoryService::build).collect(Collectors.toList()));
|
||||
return this.save(copy).getId();
|
||||
}
|
||||
|
||||
public CategoryFull buildCategory(CategoryFull categoryFull) {
|
||||
categoryFull.setSubCategories(categoryFull.getSubCategories().stream().map(this.subCategoryService::buildSubcategory).collect(Collectors.toList()));
|
||||
categoryFull.update(this.save(new Category(categoryFull)));
|
||||
return categoryFull;
|
||||
|
||||
public String copy(String id) {
|
||||
Category category = this.find(id);
|
||||
Category copy = new Category(category);
|
||||
copy.setId(null);
|
||||
copy.setSubCategories(category.getSubCategories().stream().map(this.subCategoryService::copy).collect(Collectors.toList()));
|
||||
return this.save(copy).getId();
|
||||
}
|
||||
|
||||
public Category save(Category category) {
|
||||
|
|
|
@ -58,6 +58,16 @@ public class IndicatorService {
|
|||
}
|
||||
}
|
||||
|
||||
public String build(String id) {
|
||||
return this.save(this.find(id).copy()).getId();
|
||||
}
|
||||
|
||||
public String copy(String id) {
|
||||
Indicator copy = new Indicator(this.find(id));
|
||||
copy.setId(null);
|
||||
return this.save(copy).getId();
|
||||
}
|
||||
|
||||
public Indicator save(Indicator indicator) {
|
||||
if(indicator.getId() == null) {
|
||||
indicator.setCreationDate(new Date());
|
||||
|
|
|
@ -66,12 +66,27 @@ public class SectionService {
|
|||
return this.getFullSection(type, alias, section);
|
||||
}
|
||||
|
||||
public SectionFull buildSection(SectionFull sectionFull) {
|
||||
public SectionFull saveFull(SectionFull sectionFull) {
|
||||
sectionFull.setIndicators(sectionFull.getIndicators().stream().map(this.indicatorService::save).collect(Collectors.toList()));
|
||||
Section section = this.save(new Section(sectionFull));
|
||||
return new SectionFull(section, sectionFull.getIndicators());
|
||||
}
|
||||
|
||||
public String build(String id) {
|
||||
Section section = this.find(id);
|
||||
Section copy = section.copy();
|
||||
copy.setIndicators(section.getIndicators().stream().map(this.indicatorService::build).collect(Collectors.toList()));
|
||||
return this.save(copy).getId();
|
||||
}
|
||||
|
||||
public String copy(String id) {
|
||||
Section section = this.find(id);
|
||||
Section copy = new Section(section);
|
||||
copy.setId(null);
|
||||
copy.setIndicators(section.getIndicators().stream().map(this.indicatorService::copy).collect(Collectors.toList()));
|
||||
return this.save(copy).getId();
|
||||
}
|
||||
|
||||
public Section save(Section section) {
|
||||
if (section.getId() != null) {
|
||||
section.setIndicators(this.find(section.getId()).getIndicators());
|
||||
|
@ -85,7 +100,7 @@ public class SectionService {
|
|||
|
||||
public void saveBulk(Stakeholder stakeholder, SubCategory subCategory, List<SectionFull> sections) {
|
||||
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
||||
sections = sections.stream().map(this::buildSection).collect(Collectors.toList());
|
||||
sections = sections.stream().map(this::saveFull).collect(Collectors.toList());
|
||||
sections.forEach(section -> {
|
||||
this.addSection(subCategory, section.getId());
|
||||
this.createChildren(subCategory, new Section(section), -1);
|
||||
|
|
|
@ -10,6 +10,7 @@ import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -30,10 +31,6 @@ public class StakeholderService {
|
|||
this.topicService = topicService;
|
||||
}
|
||||
|
||||
public Stakeholder find(String id) {
|
||||
return this.dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + id + " not found"));
|
||||
}
|
||||
|
||||
public Stakeholder findByAlias(String alias) {
|
||||
return this.dao.findByAlias(alias).orElseThrow(() -> new EntityNotFoundException("Stakeholder with alias: " + alias + " not found"));
|
||||
}
|
||||
|
@ -43,6 +40,9 @@ public class StakeholderService {
|
|||
}
|
||||
|
||||
public Stakeholder findByPath(String stakeholderId) {
|
||||
if(stakeholderId.equals("-1")) {
|
||||
return null;
|
||||
}
|
||||
return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,15 @@ public class StakeholderService {
|
|||
|
||||
public StakeholderFull getFullStakeholder(Stakeholder stakeholder) {
|
||||
if (this.commonService.hasVisibilityAuthority(stakeholder.getType(), stakeholder.getAlias(), stakeholder)) {
|
||||
if(!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
|
||||
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
||||
if(defaultStakeholder != null) {
|
||||
return new StakeholderFull(stakeholder,
|
||||
defaultStakeholder.getTopics().stream()
|
||||
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
return new StakeholderFull(stakeholder,
|
||||
stakeholder.getTopics().stream()
|
||||
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
||||
|
@ -91,20 +100,49 @@ public class StakeholderService {
|
|||
}
|
||||
}
|
||||
|
||||
public StakeholderFull buildStakeholder(StakeholderFull stakeholderFull) {
|
||||
stakeholderFull.setTopics(stakeholderFull.getTopics().stream().map(this.topicService::buildTopic).collect(Collectors.toList()));
|
||||
stakeholderFull.update(this.save(new Stakeholder(stakeholderFull)));
|
||||
return stakeholderFull;
|
||||
public Stakeholder buildStakeholder(Stakeholder stakeholder, String copyId) {
|
||||
if(stakeholder.getDefaultId() == null) {
|
||||
stakeholder.setCopy(false);
|
||||
if(copyId == null) {
|
||||
stakeholder.setTopics(new ArrayList<>());
|
||||
} else {
|
||||
Stakeholder copyFrom = this.findByPath(copyId);
|
||||
stakeholder.setTopics(copyFrom.getTopics().stream().map(this.topicService::copy).collect(Collectors.toList()));
|
||||
}
|
||||
} else {
|
||||
stakeholder.setTopics(new ArrayList<>());
|
||||
if(stakeholder.isCopy()) {
|
||||
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
||||
if(defaultStakeholder != null) {
|
||||
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.save(stakeholder);
|
||||
}
|
||||
|
||||
public Stakeholder save(Stakeholder stakeholder) {
|
||||
if (stakeholder.getId() != null) {
|
||||
stakeholder.setTopics(this.find(stakeholder.getId()).getTopics());
|
||||
if (!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
|
||||
stakeholder.getTopics().forEach(topic -> {
|
||||
this.topicService.delete(stakeholder.getType(), topic, false);
|
||||
});
|
||||
stakeholder.setTopics(new ArrayList<>());
|
||||
} else {
|
||||
Stakeholder old = this.findByPath(stakeholder.getId());
|
||||
stakeholder.setTopics(old.getTopics());
|
||||
if(old.getTopics().isEmpty() && old.getDefaultId() != null) {
|
||||
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
||||
if(defaultStakeholder != null) {
|
||||
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
stakeholder.getTopics().forEach(this.topicService::find);
|
||||
}
|
||||
} else {
|
||||
stakeholder.setCreationDate(new Date());
|
||||
}
|
||||
stakeholder.setUpdateDate(new Date());
|
||||
stakeholder.getTopics().forEach(this.topicService::find);
|
||||
return this.dao.save(stakeholder);
|
||||
}
|
||||
|
||||
|
@ -132,7 +170,7 @@ public class StakeholderService {
|
|||
}
|
||||
|
||||
public String delete(String id) {
|
||||
Stakeholder stakeholder = this.find(id);
|
||||
Stakeholder stakeholder = this.findByPath(id);
|
||||
if (this.commonService.hasDeleteAuthority(stakeholder.getType())) {
|
||||
this.dao.findByDefaultId(stakeholder.getId()).forEach(child -> {
|
||||
this.delete(child.getId());
|
||||
|
|
|
@ -74,11 +74,21 @@ public class SubCategoryService {
|
|||
return this.getFullSubCategory(type, alias, subCategory);
|
||||
}
|
||||
|
||||
public SubCategoryFull buildSubcategory(SubCategoryFull subCategoryFull) {
|
||||
subCategoryFull.setNumbers(subCategoryFull.getNumbers().stream().map(this.sectionService::buildSection).collect(Collectors.toList()));
|
||||
subCategoryFull.setCharts(subCategoryFull.getCharts().stream().map(this.sectionService::buildSection).collect(Collectors.toList()));
|
||||
subCategoryFull.update(this.save(new SubCategory(subCategoryFull)));
|
||||
return subCategoryFull;
|
||||
public String build(String id) {
|
||||
SubCategory subCategory = this.find(id);
|
||||
SubCategory copy = subCategory.copy();
|
||||
copy.setNumbers(subCategory.getNumbers().stream().map(this.sectionService::build).collect(Collectors.toList()));
|
||||
copy.setCharts(subCategory.getCharts().stream().map(this.sectionService::build).collect(Collectors.toList()));
|
||||
return this.save(copy).getId();
|
||||
}
|
||||
|
||||
public String copy(String id) {
|
||||
SubCategory subCategory = this.find(id);
|
||||
SubCategory copy = new SubCategory(subCategory);
|
||||
copy.setId(null);
|
||||
copy.setNumbers(subCategory.getNumbers().stream().map(this.sectionService::copy).collect(Collectors.toList()));
|
||||
copy.setCharts(subCategory.getCharts().stream().map(this.sectionService::copy).collect(Collectors.toList()));
|
||||
return this.save(copy).getId();
|
||||
}
|
||||
|
||||
public SubCategory save(SubCategory subCategory) {
|
||||
|
|
|
@ -61,10 +61,19 @@ public class TopicService {
|
|||
return this.getFullTopic(type, alias, topic);
|
||||
}
|
||||
|
||||
public TopicFull buildTopic(TopicFull topicFull) {
|
||||
topicFull.setCategories(topicFull.getCategories().stream().map(this.categoryService::buildCategory).collect(Collectors.toList()));
|
||||
topicFull.update(this.save(new Topic(topicFull)));
|
||||
return topicFull;
|
||||
public String build(String id) {
|
||||
Topic topic = this.find(id);
|
||||
Topic copy = topic.copy();
|
||||
copy.setCategories(topic.getCategories().stream().map(this.categoryService::build).collect(Collectors.toList()));
|
||||
return this.save(copy).getId();
|
||||
}
|
||||
|
||||
public String copy(String id) {
|
||||
Topic topic = this.find(id);
|
||||
Topic copy = new Topic(topic);
|
||||
copy.setId(null);
|
||||
copy.setCategories(topic.getCategories().stream().map(this.categoryService::copy).collect(Collectors.toList()));
|
||||
return this.save(copy).getId();
|
||||
}
|
||||
|
||||
public Topic save(Topic topic) {
|
||||
|
|
Loading…
Reference in New Issue