Commit fc39e540 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

added clearing aclChache after update, now removing institutes from partner also updates partner

parent c05bdcd9
......@@ -110,7 +110,7 @@ public interface PartnerService {
Partner addInstitutes(Partner partner, Set<String> instituteCodes);
boolean removeInstitutes(Set<String> instituteCodes);
Partner removeInstitutes(UUID partnerUUID, Set<String> instituteCodes);
/**
* Method for copy values of source to target.
......
......@@ -23,6 +23,7 @@ import java.util.Set;
import java.util.HashSet;
import java.util.UUID;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys.catalog.persistence.PartnerRepository;
......@@ -68,6 +69,9 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
@Autowired
private SecurityUtils securityUtils;
@Autowired
private CustomAclService aclService;
@Value("${partner.primary.uuid}")
private UUID primaryPartnerUuid;
......@@ -179,6 +183,7 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
List<FaoInstitute> institutes = instituteRepository.findAllByCodes(instituteCodes);
institutes.forEach((inst) -> inst.setOwner(partner));
institutes.forEach((institute -> aclService.createOrUpdatePermissions(institute)));
partner.getInstitutes().addAll(institutes);
return lazyLoad(partnerRepository.save(partner));
......@@ -186,13 +191,16 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
@Override
@Transactional
public boolean removeInstitutes(Set<String> instituteCodes) {
public Partner removeInstitutes(UUID partnerUuid, Set<String> instituteCodes) {
Partner partner = loadPartner(partnerUuid);
List<FaoInstitute> institutesToRemove = instituteRepository.findAllByCodes(instituteCodes);
institutesToRemove.forEach((institute -> institute.setOwner(null)));
institutesToRemove.forEach((institute -> aclService.createOrUpdatePermissions(institute)));
instituteRepository.save(institutesToRemove);
return true;
partner.getInstitutes().removeAll(institutesToRemove);
return lazyLoad(partnerRepository.save(partner));
}
/**
......
......@@ -120,9 +120,9 @@ public class PartnerController {
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@PostMapping(value = "/removeInstitutes")
public String removeInstitutes(@RequestBody Set<String> instituteCodes) {
return partnerService.removeInstitutes(instituteCodes) ? "Ok" : "Error";
@PostMapping(value = "/removeInstitutes/{UUID}")
public Partner removeInstitutes(@PathVariable("UUID") UUID uuid,@RequestBody Set<String> instituteCodes) {
return partnerService.removeInstitutes(uuid, instituteCodes);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment