Commit e7b55eb3 authored by igoshin's avatar igoshin Committed by Matija Obreza
Browse files

FaoInstitute#allowsMaterialRequests

parent a7b3858e
......@@ -90,6 +90,9 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity,
private Double elevation;
private boolean uniqueAcceNumbs = true;
@Column(name = "allowMaterialRequests", columnDefinition = "boolean default true", nullable = false)
private boolean allowMaterialRequests = true;
public FaoInstitute() {
}
......@@ -240,4 +243,12 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity,
public void setCurrent(boolean current) {
this.current = current;
}
public boolean isAllowMaterialRequests() {
return allowMaterialRequests;
}
public void setAllowMaterialRequests(boolean allowMaterialRequests) {
this.allowMaterialRequests = allowMaterialRequests;
}
}
......@@ -110,11 +110,11 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select a from Accession a where a.institute.code=:instCode and a.accessionName=:acceNumb and a.taxonomy.genus=:genus")
Accession findOne(@Param("instCode") String holdingInstitute, @Param("acceNumb") String accessionName, @Param("genus") String genus);
@Query("select count(a.id) from Accession a where a.id in ( ?1 ) and a.availability = true")
long countAvailable(Set<Long> accessionIds);
@Query("select count(a.id) from Accession a where a.id in ( ?1 ) and a.availability = true and a.institute.allowMaterialRequests = true")
long countAvailableForDistribution(Set<Long> accessionIds);
@Query("select a.id from Accession a where a.id in ( ?1 ) and a.availability = true")
Set<Long> filterAvailable(Set<Long> accessionIds);
@Query("select a.id from Accession a where a.id in ( ?1 ) and a.availability = true and a.institute.allowMaterialRequests = true")
Set<Long> filterAvailableForDistribution(Set<Long> accessionIds);
@Modifying
@Query("update Accession a set a.inSvalbard = true where a in ?1")
......
......@@ -128,9 +128,9 @@ public interface GenesysService {
List<SvalbardData> saveSvalbards(List<SvalbardData> svalbards);
long countAvailable(Set<Long> accessionIds);
long countAvailableForDistribution(Set<Long> accessionIds);
Set<Long> filterAvailable(Set<Long> accessionIds);
Set<Long> filterAvailableForDistribution(Set<Long> accessionIds);
List<Accession> saveAccession(Accession... accession);
......
......@@ -60,6 +60,8 @@ public interface InstituteService {
void setUniqueAcceNumbs(FaoInstitute faoInstitute, boolean uniqueAcceNumbs);
void setAllowMaterialRequests(FaoInstitute faoInstitute, boolean allowMaterialRequests);
void delete(String instCode);
List<FaoInstitute> listMyInstitutes(Sort sort);
......
......@@ -745,19 +745,19 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
}
@Override
public long countAvailable(Set<Long> accessionIds) {
public long countAvailableForDistribution(Set<Long> accessionIds) {
if (accessionIds == null || accessionIds.size() == 0) {
return 0;
}
return accessionRepository.countAvailable(accessionIds);
return accessionRepository.countAvailableForDistribution(accessionIds);
}
@Override
public Set<Long> filterAvailable(Set<Long> accessionIds) {
public Set<Long> filterAvailableForDistribution(Set<Long> accessionIds) {
if (accessionIds == null || accessionIds.size() == 0) {
return Collections.emptySet();
}
return accessionRepository.filterAvailable(accessionIds);
return accessionRepository.filterAvailableForDistribution(accessionIds);
}
/**
......
......@@ -146,6 +146,16 @@ 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 'uniqueAcceNumbs' to " + allowMaterialRequests + " for " + faoInstitute);
inst.setAllowMaterialRequests(allowMaterialRequests);
instituteRepository.save(inst);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')")
@Transactional(readOnly = false)
......
......@@ -102,7 +102,7 @@ public class RequestServiceImpl implements RequestService {
@Override
@Transactional
public MaterialRequest initiateRequest(RequestInfo requestInfo, Set<Long> accessionIds) throws RequestException {
final Set<Long> availableAccessionIds = genesysService.filterAvailable(accessionIds);
final Set<Long> availableAccessionIds = genesysService.filterAvailableForDistribution(accessionIds);
final Locale locale = LocaleContextHolder.getLocale();
System.err.println("Current locale: " + locale);
if (availableAccessionIds == null || availableAccessionIds.size() == 0) {
......@@ -167,7 +167,7 @@ public class RequestServiceImpl implements RequestService {
}
MaterialRequest createRequest(RequestInfo requestInfo, EasySMTA.EasySMTAUserData pid, Set<Long> accessionIds) throws RequestException {
final Set<Long> availableAccessionIds = genesysService.filterAvailable(accessionIds);
final Set<Long> availableAccessionIds = genesysService.filterAvailableForDistribution(accessionIds);
if (availableAccessionIds == null || availableAccessionIds.size() == 0) {
throw new RequestException("None of the selected accessions are available for distribution");
......
......@@ -82,7 +82,7 @@ public class RequestController extends BaseController {
model.addAttribute("blurp", contentService.getGlobalArticle("request-intro", getLocale()));
model.addAttribute("totalCount", selectionBean.size());
model.addAttribute("availableCount", genesysService.countAvailable(selectionBean.copy()));
model.addAttribute("availableCount", genesysService.countAvailableForDistribution(selectionBean.copy()));
model.addAttribute("pagedData", genesysService.listAccessions(selectionBean.copy(), new PageRequest(page - 1, 50, new Sort("accessionName"))));
return "/request/index";
......
......@@ -158,7 +158,9 @@ public class WiewsController extends BaseController {
@RequestMapping("/{wiewsCode}/update")
public String update(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam("blurp") String blurp,
@RequestParam("gaTracker") String gaTracker, @RequestParam("mailto") String mailto, @RequestParam("uniqueAcceNumbs") boolean uniqueAcceNumbs) {
@RequestParam("gaTracker") String gaTracker, @RequestParam("mailto") String mailto,
@RequestParam("uniqueAcceNumbs") boolean uniqueAcceNumbs,
@RequestParam (value = "allowMaterialRequests",required = false,defaultValue = "false") boolean allowMaterialRequests) {
_logger.debug("Updating institite " + wiewsCode);
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
......@@ -171,6 +173,7 @@ public class WiewsController extends BaseController {
settings.put("requests.mailto", mailto);
instituteService.updateSettings(faoInstitute, settings);
instituteService.setUniqueAcceNumbs(faoInstitute, uniqueAcceNumbs);
instituteService.setAllowMaterialRequests(faoInstitute, allowMaterialRequests);
return "redirect:/wiews/" + wiewsCode;
}
......
......@@ -162,6 +162,7 @@ faoInstitute.member-of-organizations-and-networks=Organizations and Networks:
faoInstitute.uniqueAcceNumbs.true=Each accession number is unique within this institute.
faoInstitute.uniqueAcceNumbs.false=The same accession number may be used in separate collections in this institute.
faoInstitute.requests.mailto=Email address for material requests:
faoInstitute.allow.requests=Allow material requests
view.accessions=View accessions...
view.datasets=View datasets...
......
......@@ -50,7 +50,7 @@
</thead>
<tbody>
<c:forEach items="${pagedData.content}" var="accession" varStatus="status">
<tr id="a${accession.id}" class="acn targeted ${status.count % 2 == 0 ? 'even' : 'odd'} ${accession.availability ? '' : 'not-available'}">
<tr id="a${accession.id}" class="acn targeted ${status.count % 2 == 0 ? 'even' : 'odd'} ${accession.availability and accession.institute.allowMaterialRequests ? '' : 'not-available'}">
<td class="idx-col">${status.count + pagedData.size * pagedData.number}</td>
<td><spring:message code="accession.availability.${accession.availability}" /></td>
<td><a href="<c:url value="/acn/id/${accession.id}" />"><b><c:out value="${accession.accessionName}" /></b></a></td>
......
......@@ -42,6 +42,9 @@
<label><input type="radio" name="uniqueAcceNumbs" class="" value="true" ${faoInstitute.uniqueAcceNumbs==true ? 'checked' : ''} /> <spring:message code="faoInstitute.uniqueAcceNumbs.true" /></label>
<label><input type="radio" name="uniqueAcceNumbs" class="" value="false" ${faoInstitute.uniqueAcceNumbs==false ? 'checked' : ''} /> <spring:message code="faoInstitute.uniqueAcceNumbs.false" /></label>
</div>
<div class="controls col-lg-offset-3 col-lg-9">
<label><input type="checkbox" name="allowMaterialRequests" class="" ${faoInstitute.allowMaterialRequests==true ? 'checked' : ''} /> <spring:message code="faoInstitute.allow.requests" /></label>
</div>
</div>
<input type="submit" value="<spring:message code="save"/>" class="btn btn-primary" /> <a href="<c:url value="/wiews/${faoInstitute.code}" />" class="btn btn-default"> <spring:message code="cancel" />
......
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