Search in sources :

Example 11 with Version

use of org.openforis.commons.versioning.Version in project collect by openforis.

the class CollectInfoService method latestRelease.

private Version latestRelease() {
    try {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpGet request = new HttpGet(LATEST_RELEASE_MAVEN_METADATA_URL);
        request.setConfig(RequestConfig.custom().setConnectTimeout(RELEASE_FETCH_TIMEOUT).build());
        CloseableHttpResponse response = client.execute(request);
        try {
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(is);
            doc.getDocumentElement().normalize();
            Element versioningElement = (Element) doc.getElementsByTagName("versioning").item(0);
            NodeList releaseNodeList = versioningElement.getElementsByTagName("release");
            if (releaseNodeList.getLength() == 1) {
                Node releaseNode = releaseNodeList.item(0).getFirstChild();
                String release = releaseNode.getNodeValue();
                return new Version(release);
            }
        } finally {
            response.close();
        }
    } catch (Exception e) {
    }
    return null;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HttpEntity(org.apache.http.HttpEntity) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Version(org.openforis.commons.versioning.Version) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Aggregations

Version (org.openforis.commons.versioning.Version)11 CollectCompleteInfo (org.openforis.collect.CollectCompleteInfo)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 IdmlParseException (org.openforis.idm.metamodel.xml.IdmlParseException)2 InputStream (java.io.InputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 SurveyBackupInfo (org.openforis.collect.io.SurveyBackupInfo)1 ApplicationInfo (org.openforis.collect.model.ApplicationInfo)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 ModelVersion (org.openforis.idm.metamodel.ModelVersion)1 Schema (org.openforis.idm.metamodel.Schema)1 Entity (org.openforis.idm.model.Entity)1 ModelSerializer (org.openforis.idm.model.ModelSerializer)1 Document (org.w3c.dom.Document)1