Commit 66c2a304 authored by Alexander Prendetskiy's avatar Alexander Prendetskiy Committed by Matija Obreza

add ApiInfoController to v1

parent d62a988d
...@@ -172,4 +172,11 @@ public interface DescriptorService { ...@@ -172,4 +172,11 @@ public interface DescriptorService {
Descriptor nextVersion(@P("descriptor") Descriptor descriptor, boolean major); Descriptor nextVersion(@P("descriptor") Descriptor descriptor, boolean major);
void exportDescriptors(DescriptorFilter filter, OutputStream outputStream) throws IOException; void exportDescriptors(DescriptorFilter filter, OutputStream outputStream) throws IOException;
/**
* Cont published descriptors
*
* @return the number of published descriptors
*/
long countPublished();
} }
...@@ -112,4 +112,6 @@ public interface PartnerService { ...@@ -112,4 +112,6 @@ public interface PartnerService {
*/ */
Partner removePartner(Partner partner); Partner removePartner(Partner partner);
long countPartners(PartnerFilter filter);
} }
...@@ -457,4 +457,9 @@ public class DescriptorServiceImpl implements DescriptorService { ...@@ -457,4 +457,9 @@ public class DescriptorServiceImpl implements DescriptorService {
downloadService.writeXlsxDescriptor(descriptors, outputStream); downloadService.writeXlsxDescriptor(descriptors, outputStream);
} }
@Override
public long countPublished() {
return descriptorRepository.count(descriptor.state.eq(PublishState.PUBLISHED));
}
} }
...@@ -26,6 +26,7 @@ import org.genesys.catalog.persistence.PartnerRepository; ...@@ -26,6 +26,7 @@ import org.genesys.catalog.persistence.PartnerRepository;
import org.genesys.catalog.service.PartnerService; import org.genesys.catalog.service.PartnerService;
import org.genesys2.server.model.UserRole; import org.genesys2.server.model.UserRole;
import org.genesys2.server.security.SecurityUtils; import org.genesys2.server.security.SecurityUtils;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.util.JPAUtils; import org.genesys2.util.JPAUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -58,6 +59,9 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean { ...@@ -58,6 +59,9 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
@Autowired @Autowired
private SecurityUtils securityUtils; private SecurityUtils securityUtils;
@Autowired
private ElasticsearchService elasticsearchService;
@Value("${partner.primary.uuid}") @Value("${partner.primary.uuid}")
private UUID primaryPartnerUuid; private UUID primaryPartnerUuid;
...@@ -220,6 +224,18 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean { ...@@ -220,6 +224,18 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
return loadedPartner; return loadedPartner;
} }
@Override
public long countPartners(PartnerFilter filter) {
long total = elasticsearchService.count(Partner.class, filter);
if (total < 10000) {
// If total is below 10K, use actual count
total = partnerRepository.count(filter.buildQuery());
}
return total;
}
/** /**
* Lazy load. * Lazy load.
* *
......
package org.genesys2.server.api.v1;
import io.swagger.annotations.Api;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.PartnerService;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.service.AccessionService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.net.UnknownHostException;
/**
* Accession API v1
*/
@RestController("infoApi1")
@PreAuthorize("isAuthenticated()")
@RequestMapping(ApiInfoController.CONTROLLER_URL)
@Api(tags = { "api-info" })
public class ApiInfoController {
private static final Logger LOG = LoggerFactory.getLogger(ApiInfoController.class);
public static final String CONTROLLER_URL = ApiBaseController.APIv1_BASE + "/info";
@Value("${build.version}")
private String version;
@Value("${build.artifactId}")
private String artifactId;
@Value("${build.revision}")
private String revision;
@Value("${cdn.servers}")
private String[] cdnServers;
@Autowired
private AccessionService accessionService;
@Autowired
private DatasetService datasetService;
@Autowired
private SubsetService subsetService;
@Autowired
private InstituteService instituteService;
@Autowired
private DescriptorService descriptorService;
@Autowired
private PartnerService partnerService;
/**
* Api info.
*
* @return the api info
*/
@RequestMapping(value = "/version", method = RequestMethod.GET)
public ApiInfo apiInfo() {
String hN;
try {
hN = java.net.InetAddress.getLocalHost().getHostName();
} catch (final UnknownHostException e) {
LOG.error("Error getting Host Name");
hN = "";
}
ApiInfo apiInfo = new ApiInfo();
apiInfo.version = this.version;
apiInfo.artifactId = this.artifactId;
apiInfo.revision = this.revision;
apiInfo.cdnServers = this.cdnServers;
apiInfo.hostName = hN;
apiInfo.accessionCount = accessionService.countAccessions(new AccessionFilter());
apiInfo.datasetCount = datasetService.countPublished();
apiInfo.subsetCount = subsetService.countPublished();
apiInfo.instituteCount = instituteService.countActive();
apiInfo.descriptorCount = descriptorService.countPublished();
apiInfo.partnerCount = partnerService.countPartners(new PartnerFilter());
return apiInfo;
}
/**
* The Class ApiInfo.
*/
public static class ApiInfo {
public String artifactId;
public String version;
public String revision;
public String hostName;
public String[] cdnServers;
public long accessionCount;
public long datasetCount;
public long subsetCount;
public long instituteCount;
public long descriptorCount;
public long partnerCount;
}
}
...@@ -42,6 +42,13 @@ public interface SubsetService { ...@@ -42,6 +42,13 @@ public interface SubsetService {
*/ */
Page<Subset> list(SubsetFilter filter, Pageable page); Page<Subset> list(SubsetFilter filter, Pageable page);
/**
* Cont published subsets
*
* @return the number of published subsets
*/
long countPublished();
/** /**
* List current user's subsets matching the filter. * List current user's subsets matching the filter.
* *
......
...@@ -98,6 +98,11 @@ public class SubsetServiceImpl implements SubsetService { ...@@ -98,6 +98,11 @@ public class SubsetServiceImpl implements SubsetService {
return subsetRepository.findAll(published, page); return subsetRepository.findAll(published, page);
} }
@Override
public long countPublished() {
return subsetRepository.count(QSubset.subset.state.eq(PublishState.PUBLISHED));
}
@Override @Override
@PreAuthorize("hasRole('ADMINISTRATOR') or isAuthenticated()") @PreAuthorize("hasRole('ADMINISTRATOR') or isAuthenticated()")
public Page<Subset> listSubsetsForCurrentUser(SubsetFilter filter, Pageable page) { public Page<Subset> listSubsetsForCurrentUser(SubsetFilter filter, Pageable page) {
......
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