Commit 6642332d authored by Matija Obreza's avatar Matija Obreza

Removed unused statisticsPheno in WIEWS details

parent ff0767f5
......@@ -35,6 +35,7 @@ import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.time.StopWatch;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
......@@ -51,6 +52,7 @@ import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.DownloadService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.ElasticsearchService.TermResult;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
......@@ -165,6 +167,7 @@ public class WiewsController extends BaseController {
@RequestMapping("/{wiewsCode}")
public String view(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode) {
StopWatch stopWatch = StopWatch.createStarted();
LOG.debug("Viewing institute {}", wiewsCode);
if (!wiewsCode.toUpperCase().equals(wiewsCode)) {
......@@ -177,12 +180,15 @@ public class WiewsController extends BaseController {
}
model.addAttribute("faoInstitute", faoInstitute);
model.addAttribute("organizations", organizationService.getOrganizations(faoInstitute));
LOG.trace("organizations after {}ms", stopWatch.getTime());
model.addAttribute("blurp", contentService.getArticle(faoInstitute, "blurp", getLocale()));
LOG.trace("blurp after {}ms", stopWatch.getTime());
model.addAttribute("countByInstitute", faoInstitute.getAccessionCount());
LOG.trace("countByInstitute after {}ms", stopWatch.getTime());
long datasetCount = genesysService.countDatasets(faoInstitute);
model.addAttribute("datasetCount", datasetCount);
LOG.trace("datasetCount after {}ms", stopWatch.getTime());
{
AccessionFilter af=new AccessionFilter();
......@@ -190,23 +196,29 @@ public class WiewsController extends BaseController {
af.historic = false;
try {
model.addAttribute("statisticsCrops", elasticService.termStatisticsAuto(Accession.class, af, 5, AppliedFiltersConverter
Map<String, TermResult> esStats = elasticService.termStatisticsAuto(Accession.class, af, 5, AppliedFiltersConverter
.convertTerm(FilterConstants.CROPS), AppliedFiltersConverter
.convertTerm(FilterConstants.CROPNAME), AppliedFiltersConverter
.convertTerm(FilterConstants.TAXONOMY_GENUS));
LOG.trace("ES statistics after {}ms", stopWatch.getTime());
model.addAttribute("statisticsCrops", esStats.get(AppliedFiltersConverter
.convertTerm(FilterConstants.CROPS)));
model.addAttribute("statisticsCropName", elasticService.termStatisticsAuto(Accession.class, af, 5, AppliedFiltersConverter
model.addAttribute("statisticsCropName", esStats.get(AppliedFiltersConverter
.convertTerm(FilterConstants.CROPNAME)));
model.addAttribute("statisticsGenus", elasticService.termStatisticsAuto(Accession.class, af, 5, AppliedFiltersConverter
model.addAttribute("statisticsGenus", esStats.get(AppliedFiltersConverter
.convertTerm(FilterConstants.TAXONOMY_GENUS)));
} catch (SearchException e) {
LOG.warn(e.getMessage());
}
}
model.addAttribute("statisticsTaxonomy", genesysService.statisticsSpeciesByInstituteES(faoInstitute, 5));
LOG.trace("statisticsTaxonomy after {}ms", stopWatch.getTime());
model.addAttribute("statisticsPDCI", faoInstitute.getStatisticsPDCI());
LOG.trace("statisticsPDCI after {}ms", stopWatch.getTime());
model.addAttribute("updates", genesysService.getLastUpdatedStatistics(faoInstitute));
if (datasetCount > 0) {
model.addAttribute("statisticsPheno", statisticsService.statisticsPheno(faoInstitute));
}
LOG.trace("updates after {}ms", stopWatch.getTime());
return "/wiews/details";
}
......
......@@ -40,7 +40,6 @@ import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.PDCI;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.genesys.PhenoStatistics;
import org.genesys2.server.model.genesys.SvalbardDeposit;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.AccessionIdentifier3;
......@@ -233,8 +232,6 @@ public interface GenesysService {
PDCIStatistics statisticsPDCI(Organization organization);
PhenoStatistics statisticsPheno(FaoInstitute faoInstitute);
void regenerateAccessionSequentialNumber();
List<SvalbardDeposit> saveSvalbards(List<SvalbardDeposit> svalbards);
......
......@@ -37,6 +37,4 @@ public interface StatisticsService {
PDCIStatistics statisticsPDCI(Organization organization);
PhenoStatistics statisticsPheno(FaoInstitute faoInstitute);
}
......@@ -22,23 +22,47 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.persistence.EntityManager;
import com.google.common.collect.Sets;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.blocks.security.model.AclSid;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.*;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
import org.genesys2.server.model.genesys.AccessionData;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionHistoric;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.genesys.AccessionTrait;
import org.genesys2.server.model.genesys.AllAccnames;
import org.genesys2.server.model.genesys.ExperimentAccessionTrait;
import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.PDCI;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.genesys.SelfCopy;
import org.genesys2.server.model.genesys.SvalbardDeposit;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.genesys.TraitCode;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.Crop;
......@@ -90,9 +114,11 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Sets;
import com.opencsv.CSVWriter;
import com.opencsv.ResultSetHelper;
import com.opencsv.ResultSetHelperService;
import com.querydsl.jpa.impl.JPAQueryFactory;
@Service
@Transactional(readOnly = true)
......@@ -1447,43 +1473,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return stats;
}
@Override
public PhenoStatistics statisticsPheno(FaoInstitute faoInstitute) {
List<Object[]> metadatas = accessionTraitRepository.statisticsAccessionMetadata(faoInstitute);
List<Object[]> methods = accessionTraitRepository.statisticsAccessionMethod(faoInstitute);
long count = countByInstitute(faoInstitute);
PhenoStatistics stats = new PhenoStatistics();
stats.setCount(count);
{
long withMetadata = 0, metadatasTotal = 0;
for (Object[] m : metadatas) {
// Long accessionId = (Long) m[0];
Long metadataCount = (Long) m[1];
if (metadataCount != null && metadataCount > 0) {
withMetadata++;
metadatasTotal += metadataCount;
}
}
stats.setWithMetadata(withMetadata);
stats.setAvgMetadatas((float) metadatasTotal / withMetadata);
}
{
long withMethod = 0, methodsTotal = 0;
for (Object[] m : methods) {
// Long accessionId = (Long) m[0];
Long methodCount = (Long) m[1];
if (methodCount != null && methodCount > 0) {
withMethod++;
methodsTotal += methodCount;
}
}
stats.setWithMethod(withMethod);
stats.setAvgMethods((float) methodsTotal / withMethod);
}
return stats;
}
@Transactional(readOnly = false)
@Override
......
......@@ -21,8 +21,6 @@ import org.genesys.catalog.service.DatasetService;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.genesys.PhenoStatistics;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.GenesysService;
......@@ -109,15 +107,4 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
@Override
@Cacheable(unless = "#result == null", value = "statistics", key = "'stats.' + #root.methodName + '-' + #faoInstitute.id")
public PhenoStatistics statisticsPheno(FaoInstitute faoInstitute) {
synchronized (this) {
if (LOG.isDebugEnabled()) {
LOG.debug("Regenerating C&E statistics for {}", faoInstitute);
}
return genesysService.statisticsPheno(faoInstitute);
}
}
}
......@@ -26,10 +26,6 @@ import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys.catalog.persistence.PartnerRepository;
import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.persistence.traits.DescriptorListRepository;
import org.genesys.catalog.persistence.traits.DescriptorRepository;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.persistence.UserRepository;
......@@ -99,12 +95,6 @@ public class ApplicationStartup implements InitializingBean, ApplicationListener
}
startup();
asAdminInvoker.invoke(() -> {
aclForCatalog();
// aclParentObject();
return null;
});
}
/**
......@@ -178,32 +168,6 @@ public class ApplicationStartup implements InitializingBean, ApplicationListener
LOG.info("Startup initializer done.");
}
@Autowired
private PartnerRepository partnerRepository;
@Autowired
private DatasetRepository datasetRepository;
@Autowired
private DescriptorRepository descriptorRepository;
@Autowired
private DescriptorListRepository descriptorListRepository;
// TODO Remove after first deployment to sandbox
private void aclForCatalog() {
partnerRepository.findAll().stream().forEach(partner -> aclService.addCreatorPermissions(partner));
// datasetRepository.findAll().stream().forEach(dataset ->
// aclService.removeAclAwareModel(dataset));
datasetRepository.findAll().stream().forEach(dataset -> aclService.addCreatorPermissions(dataset));
// descriptorListRepository.findAll().stream().forEach(descriptorList ->
// aclService.removeAclAwareModel(descriptorList));
descriptorListRepository.findAll().stream().forEach(descriptorList -> aclService.addCreatorPermissions(descriptorList));
// descriptorRepository.findAll().stream().forEach(descriptor ->
// aclService.removeAclAwareModel(descriptor));
descriptorRepository.findAll().stream().forEach(descriptor -> aclService.addCreatorPermissions(descriptor));
}
@Autowired
private ElasticsearchService elasticsearch;
......
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