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

Caching enabled in OrganizationService, moved...

Caching enabled in OrganizationService, moved InstituteService#getOrganizations to OrganizationService
parent 4e432938
......@@ -23,7 +23,6 @@ import java.util.Map;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
......@@ -52,8 +51,6 @@ public interface InstituteService {
void updateCountryRefs();
List<Organization> getOrganizations(FaoInstitute faoInstitute);
void setCodeSGSV(FaoInstitute faoInstitute, String codeSGSV);
void updateSettings(FaoInstitute faoInstitute, Map<String, String> settings);
......
......@@ -53,4 +53,6 @@ public interface OrganizationService {
Organization deleteOrganization(Organization organization);
Article getBlurp(Organization organization, Locale locale);
List<Organization> getOrganizations(FaoInstitute institute);
}
......@@ -29,12 +29,10 @@ import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.FaoInstituteSetting;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.persistence.domain.CountryRepository;
import org.genesys2.server.persistence.domain.FaoInstituteRepository;
import org.genesys2.server.persistence.domain.FaoInstituteSettingRepository;
import org.genesys2.server.persistence.domain.GenesysLowlevelRepository;
import org.genesys2.server.persistence.domain.OrganizationRepository;
import org.genesys2.server.security.AuthUserDetails;
import org.genesys2.server.service.AclService;
import org.genesys2.server.service.ContentService;
......@@ -76,9 +74,6 @@ public class InstituteServiceImpl implements InstituteService {
@Autowired
private GenesysLowlevelRepository genesysLowlevelRepository;
@Autowired
private OrganizationRepository organizationRepository;
@Autowired
private AclService aclService;
......@@ -100,9 +95,6 @@ public class InstituteServiceImpl implements InstituteService {
@Override
public FaoInstitute getInstitute(String wiewsCode) {
final FaoInstitute inst = instituteRepository.findByCode(wiewsCode);
if (inst != null) {
inst.getSettings().size();
}
return inst;
}
......@@ -204,14 +196,6 @@ public class InstituteServiceImpl implements InstituteService {
genesysLowlevelRepository.updateFaoInstituteCountries();
}
@Override
public List<Organization> getOrganizations(FaoInstitute faoInstitute) {
if (faoInstitute == null) {
throw new NullPointerException("faoInstitute");
}
return organizationRepository.getOrganizations(faoInstitute);
}
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
......
......@@ -32,6 +32,8 @@ import org.genesys2.server.persistence.domain.OrganizationRepository;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.OrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -41,6 +43,8 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
public class OrganizationServiceImpl implements OrganizationService {
private static final String CACHE_ORGANIZATION_INSTITUTEORGS = "hibernate.org.genesys2.server.model.impl.Organization.instituteOrganizations";
public static final Log LOG = LogFactory.getLog(OrganizationServiceImpl.class);
@Autowired
......@@ -60,6 +64,7 @@ public class OrganizationServiceImpl implements OrganizationService {
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Override
@Transactional
@CacheEvict(value = CACHE_ORGANIZATION_INSTITUTEORGS, allEntries = true)
public Organization deleteOrganization(Organization organization) {
organization = organizationRepository.findOne(organization.getId());
organizationRepository.delete(organization);
......@@ -120,6 +125,7 @@ public class OrganizationServiceImpl implements OrganizationService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = CACHE_ORGANIZATION_INSTITUTEORGS, allEntries = true)
public boolean setOrganizationInstitutes(Organization org, List<String> instituteList) {
LOG.info("Setting institutes for organization " + org);
......@@ -171,6 +177,7 @@ public class OrganizationServiceImpl implements OrganizationService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = CACHE_ORGANIZATION_INSTITUTEORGS, allEntries=true)
public boolean addOrganizationInstitutes(final Organization organization, final List<String> instituteList) {
LOG.info("Adding institutes to organization " + organization);
......@@ -200,4 +207,13 @@ public class OrganizationServiceImpl implements OrganizationService {
return updated;
}
@Override
@Cacheable(value = CACHE_ORGANIZATION_INSTITUTEORGS, key = "#faoInstitute.id")
public List<Organization> getOrganizations(FaoInstitute faoInstitute) {
if (faoInstitute == null) {
throw new NullPointerException("faoInstitute");
}
return organizationRepository.getOrganizations(faoInstitute);
}
}
......@@ -34,6 +34,7 @@ import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
......@@ -53,17 +54,16 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fasterxml.jackson.databind.ObjectMapper;
@Controller
@Scope("request")
@RequestMapping("/wiews")
public class WiewsController extends BaseController {
private final ObjectMapper mapper = new ObjectMapper();
@Autowired
private InstituteService instituteService;
@Autowired
private OrganizationService organizationService;
@Autowired
private GenesysService genesysService;
......@@ -110,7 +110,7 @@ public class WiewsController extends BaseController {
throw new ResourceNotFoundException();
}
model.addAttribute("faoInstitute", faoInstitute);
model.addAttribute("organizations", instituteService.getOrganizations(faoInstitute));
model.addAttribute("organizations", organizationService.getOrganizations(faoInstitute));
model.addAttribute("blurp", contentService.getArticle(faoInstitute, "blurp", getLocale()));
......
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