ApiInfoController.java
package org.genesys.server.api.v1;
import org.genesys.server.api.ApiBaseController;
import org.genesys.server.model.PublishState;
import org.genesys.server.model.filters.DatasetFilter;
import org.genesys.server.model.filters.DescriptorFilter;
import org.genesys.server.model.filters.DescriptorListFilter;
import org.genesys.server.model.filters.PartnerFilter;
import org.genesys.server.service.AccessionService;
import org.genesys.server.service.DatasetService;
import org.genesys.server.service.DescriptorListService;
import org.genesys.server.service.DescriptorService;
import org.genesys.server.service.InstituteService;
import org.genesys.server.service.PartnerService;
import org.genesys.server.service.SubsetService;
import org.genesys.server.service.filter.AccessionFilter;
import org.genesys.server.service.filter.SubsetFilter;
import org.genesys.server.exception.SearchException;
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 io.swagger.annotations.Api;
/**
* Accession API v1
*/
@RestController("infoApi1")
@PreAuthorize("isAuthenticated()")
@RequestMapping(ApiInfoController.CONTROLLER_URL)
@Api(tags = { "api-info" })
public class ApiInfoController {
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("${base.url}")
private String baseUrl;
@Value("${cdn.servers}")
private String[] cdnServers;
@Value("${captcha.siteKey}")
private String captchaSiteKey;
@Value("${google.analytics.account}")
private String googleAnalyticsId;
@Value("${itpgrfa.glis.basepath}")
private String glisUrl;
@Value("${frontend.url}")
private String frontendUrl;
@Autowired
private AccessionService accessionService;
@Autowired
private DatasetService datasetService;
@Autowired
private SubsetService subsetService;
@Autowired
private InstituteService instituteService;
@Autowired
private DescriptorService descriptorService;
@Autowired
private DescriptorListService descriptorListService;
@Autowired
private PartnerService partnerService;
/**
* Api info.
*
* @return the api info
*/
@RequestMapping(value = "/version", method = RequestMethod.GET)
public ApiInfo apiInfo() throws SearchException {
ApiInfo apiInfo = new ApiInfo();
apiInfo.version = this.version;
apiInfo.artifactId = this.artifactId;
apiInfo.revision = this.revision;
apiInfo.cdnServers = this.cdnServers;
apiInfo.baseUrl = this.baseUrl;
apiInfo.publicWebsiteUrl = this.frontendUrl;
apiInfo.accessionCount = accessionService.countAccessions(new AccessionFilter().historic(false));
apiInfo.datasetCount = datasetService.countDatasets(new DatasetFilter().state(PublishState.PUBLISHED).current(true));
apiInfo.subsetCount = subsetService.countSubsets(new SubsetFilter().state(PublishState.PUBLISHED).current(true));
apiInfo.instituteCount = instituteService.countActive();
apiInfo.descriptorCount = descriptorService.countDescriptors(new DescriptorFilter().state(PublishState.PUBLISHED));
apiInfo.descriptorListCount = descriptorListService.countDescriptorLists(new DescriptorListFilter().state(PublishState.PUBLISHED));
apiInfo.partnerCount = partnerService.countPartners(new PartnerFilter());
apiInfo.captchaSiteKey = this.captchaSiteKey;
apiInfo.googleAnalyticsId = this.googleAnalyticsId;
apiInfo.glisUrl = this.glisUrl;
return apiInfo;
}
/**
* The Class ApiInfo.
*/
public static class ApiInfo {
public String artifactId;
public String version;
public String revision;
public String baseUrl;
public String publicWebsiteUrl;
public String[] cdnServers;
public long instituteCount;
public long accessionCount;
public long datasetCount;
public long subsetCount;
public long descriptorListCount;
public long descriptorCount;
public long partnerCount;
public String captchaSiteKey;
public String googleAnalyticsId;
public String glisUrl;
}
}