Commit ac3c7d4e authored by Matija Obreza's avatar Matija Obreza
Browse files

InstituteService#findInstitute also loads FaoInstitute#settings

parent c08fd432
......@@ -36,6 +36,7 @@ public interface InstituteService {
Page<FaoInstitute> list(Pageable p);
FaoInstitute getInstitute(String wiewsCode);
FaoInstitute findInstitute(String wiewsCode);
List<FaoInstitute> getInstitutes(Collection<String> wiewsCodes);
......
......@@ -91,10 +91,18 @@ public class InstituteServiceImpl implements InstituteService {
public long countActive() {
return instituteRepository.countActive();
}
@Override
public FaoInstitute getInstitute(String wiewsCode) {
return instituteRepository.findByCode(wiewsCode);
}
@Override
public FaoInstitute findInstitute(String wiewsCode) {
final FaoInstitute inst = instituteRepository.findByCode(wiewsCode);
if (inst != null) {
inst.getSettings().size();
}
return inst;
}
......@@ -140,27 +148,27 @@ public class InstituteServiceImpl implements InstituteService {
instituteRepository.save(inst);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')")
@Transactional(readOnly = false)
public void setAllowMaterialRequests(FaoInstitute faoInstitute, boolean allowMaterialRequests) {
final FaoInstitute inst = instituteRepository.findOne(faoInstitute.getId());
LOG.info("Setting 'allowMaterialRequests' to " + allowMaterialRequests + " for " + faoInstitute);
inst.setAllowMaterialRequests(allowMaterialRequests);
instituteRepository.save(inst);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')")
@Transactional(readOnly = false)
public void setCodeSGSV(FaoInstitute faoInstitute, String codeSGSV) {
final FaoInstitute inst = instituteRepository.findOne(faoInstitute.getId());
LOG.info("Setting 'codeSGSV' to " + codeSGSV + " for " + faoInstitute);
inst.setCodeSGSV(codeSGSV);
instituteRepository.save(inst);
}
@Override
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')")
@Transactional(readOnly = false)
public void setAllowMaterialRequests(FaoInstitute faoInstitute, boolean allowMaterialRequests) {
final FaoInstitute inst = instituteRepository.findOne(faoInstitute.getId());
LOG.info("Setting 'allowMaterialRequests' to " + allowMaterialRequests + " for " + faoInstitute);
inst.setAllowMaterialRequests(allowMaterialRequests);
instituteRepository.save(inst);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')")
@Transactional(readOnly = false)
public void setCodeSGSV(FaoInstitute faoInstitute, String codeSGSV) {
final FaoInstitute inst = instituteRepository.findOne(faoInstitute.getId());
LOG.info("Setting 'codeSGSV' to " + codeSGSV + " for " + faoInstitute);
inst.setCodeSGSV(codeSGSV);
instituteRepository.save(inst);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')")
@Transactional(readOnly = false)
public void updateSettings(FaoInstitute faoInstitute, Map<String, String> settings) {
......
......@@ -105,7 +105,7 @@ public class AccessionController extends BaseController {
public String viewInstituteAccession(ModelMap model, @PathVariable(value = "holdingInstitute") String holdingInstitute,
@PathVariable(value = "accessionName") String accessionName) {
_logger.debug("Viewing ACN " + accessionName);
final FaoInstitute faoInstitute = instituteService.getInstitute(holdingInstitute);
final FaoInstitute faoInstitute = instituteService.findInstitute(holdingInstitute);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
......
......@@ -75,7 +75,7 @@ public class DatasetController extends BaseController {
model.addAttribute("metadata", metadata);
model.addAttribute("methods", genesysService.listMethods(metadata));
final FaoInstitute faoInstitute = instituteService.getInstitute(metadata.getInstituteCode());
final FaoInstitute faoInstitute = instituteService.findInstitute(metadata.getInstituteCode());
model.addAttribute("faoInstitute", faoInstitute);
final Page<Accession> accessions = genesysService.listMetadataAccessions(metadata.getId(), new PageRequest(page - 1, 50));
......
......@@ -105,7 +105,7 @@ public class WiewsController extends BaseController {
return "redirect:/wiews/" + wiewsCode.toUpperCase();
}
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
final FaoInstitute faoInstitute = instituteService.findInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
......
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