Commit 0ea82abc authored by Matija Obreza's avatar Matija Obreza

findById(Set<Long) restored, method names fixed, allowMaterialRequests checked...

findById(Set<Long) restored, method names fixed, allowMaterialRequests checked in filterAvailableForDistribution and countAvailableForDistribution
parent 9edda553
......@@ -92,7 +92,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
List<Accession> findByInstituteAndAccessionName(FaoInstitute faoInstitute, String accessionName);
@Query("from Accession a where a.institute.allowMaterialRequests=true and a.id in ( ?1 )")
@Query("from Accession a where a.id in ( ?1 )")
Page<Accession> findById(Collection<Long> accessionIds, Pageable pageable);
@Query("from Accession a where a.id in ( ?1 )")
......@@ -111,10 +111,10 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
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);
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,7 +60,7 @@ public interface InstituteService {
void setUniqueAcceNumbs(FaoInstitute faoInstitute, boolean uniqueAcceNumbs);
void setallowMaterialRequests(FaoInstitute faoInstitute, boolean allowMaterialRequests);
void setAllowMaterialRequests(FaoInstitute faoInstitute, boolean allowMaterialRequests);
void delete(String instCode);
......
......@@ -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);
}
/**
......
......@@ -149,7 +149,7 @@ public class InstituteServiceImpl implements InstituteService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')")
@Transactional(readOnly = false)
public void setallowMaterialRequests(FaoInstitute faoInstitute, boolean allowMaterialRequests) {
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);
......
......@@ -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";
......
......@@ -173,7 +173,7 @@ public class WiewsController extends BaseController {
settings.put("requests.mailto", mailto);
instituteService.updateSettings(faoInstitute, settings);
instituteService.setUniqueAcceNumbs(faoInstitute, uniqueAcceNumbs);
instituteService.setallowMaterialRequests(faoInstitute, allowMaterialRequests);
instituteService.setAllowMaterialRequests(faoInstitute, allowMaterialRequests);
return "redirect:/wiews/" + wiewsCode;
}
......
......@@ -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>
......
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