Search in sources :

Example 41 with HttpEntity

use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.

the class palodimensions method createDimension.

public palodimension createDimension(String strDimensionName, int iType) throws paloexception {
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("sid", this.plConn.getPaloToken()));
    qparams.add(new BasicNameValuePair("database", String.valueOf(this.plDB.getDatabaseId())));
    qparams.add(new BasicNameValuePair("new_name", strDimensionName));
    qparams.add(new BasicNameValuePair("type", String.valueOf(iType)));
    try {
        HttpEntity entity = this.plConn.sendToServer(qparams, "/dimension/create");
        CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
        csv.setQuoteChar('"');
        csv.readNext();
        palodimension plDim = new palodimension(this.plConn, this.plDB.getDatabaseId(), csv.get(1), palohelpers.StringToInt(csv.get(0)), palohelpers.StringToInt(csv.get(7)), palohelpers.StringToInt(csv.get(8)), palohelpers.StringToInt(csv.get(9)), palohelpers.StringToInt(csv.get(2)), palohelpers.StringToInt(csv.get(3)), palohelpers.StringToInt(csv.get(4)), palohelpers.StringToInt(csv.get(5)), palohelpers.StringToInt(csv.get(10)));
        paloDimensions.add(plDim);
        csv.close();
        entity.consumeContent();
        return plDim;
    } catch (Exception e) {
        throw new paloexception(e.getMessage());
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 42 with HttpEntity

use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.

the class paloelement method rename.

public void rename(String strElementNewName) throws paloexception {
    if (null != strElementNewName && strElementNewName.length() > 0 && !strElementName.equals(strElementNewName)) {
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("sid", this.plConn.getPaloToken()));
        qparams.add(new BasicNameValuePair("database", String.valueOf(lDatabaseId)));
        qparams.add(new BasicNameValuePair("dimension", String.valueOf(this.iDimensionId)));
        qparams.add(new BasicNameValuePair("element", String.valueOf(this.lElementIdentifier)));
        qparams.add(new BasicNameValuePair("new_name", strElementNewName));
        try {
            HttpEntity entity = this.plConn.sendToServer(qparams, "/element/rename");
            CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
            csv.setQuoteChar('"');
            csv.readNext();
            this.strElementName = csv.get(1);
            csv.close();
            entity.consumeContent();
        } catch (Exception e) {
            throw new paloexception(e.getMessage());
        }
        strElementName = strElementNewName;
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 43 with HttpEntity

use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.

the class paloelement method move.

public void move(long lElementNewPosition) throws paloexception {
    if (lElementNewPosition > -1 && lElementNewPosition != iElementPosition) {
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("sid", this.plConn.getPaloToken()));
        qparams.add(new BasicNameValuePair("database", String.valueOf(lDatabaseId)));
        qparams.add(new BasicNameValuePair("dimension", String.valueOf(this.iDimensionId)));
        qparams.add(new BasicNameValuePair("element", String.valueOf(this.lElementIdentifier)));
        qparams.add(new BasicNameValuePair("position", String.valueOf(lElementNewPosition)));
        try {
            HttpEntity entity = this.plConn.sendToServer(qparams, "/element/move");
            CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
            csv.setQuoteChar('"');
            while (csv.readNext()) {
                this.lElementIdentifier = palohelpers.StringToLong(csv.get(0));
                this.strElementName = csv.get(1);
                this.iElementPosition = palohelpers.StringToInt(csv.get(2));
                this.iElementLevel = palohelpers.StringToInt(csv.get(3));
                this.iElementIndent = palohelpers.StringToInt(csv.get(4));
                this.iElementDepth = palohelpers.StringToInt(csv.get(5));
                this.iElementType = palohelpers.StringToInt(csv.get(6));
                this.iElementNumOfParents = palohelpers.StringToInt(csv.get(7));
                this.iArrElementParents = palohelpers.StringToIntArray(csv.get(8), palohelpers.StringToInt(csv.get(7)));
                this.iElementNumOfChildren = palohelpers.StringToInt(csv.get(9));
                this.iArrElementChildren = palohelpers.StringToIntArray(csv.get(10), palohelpers.StringToInt(csv.get(9)));
                this.dArrElementChildrenWeights = palohelpers.StringToDoubleArray(csv.get(11), palohelpers.StringToInt(csv.get(9)));
            }
            csv.close();
            entity.consumeContent();
        } catch (Exception e) {
            throw new paloexception(e.getMessage());
        }
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 44 with HttpEntity

use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.

the class paloelement method getFatherPaloelement.

// get father paloelement
public paloelement getFatherPaloelement() throws paloexception {
    long identifier = getElementParentIdentifier();
    paloelement plElm = null;
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("sid", this.plConn.getPaloToken()));
    qparams.add(new BasicNameValuePair("database", String.valueOf(lDatabaseId)));
    qparams.add(new BasicNameValuePair("dimension", String.valueOf(this.iDimensionId)));
    qparams.add(new BasicNameValuePair("element", String.valueOf(identifier)));
    try {
        HttpEntity entity = this.plConn.sendToServer(qparams, "/element/info");
        CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
        csv.setQuoteChar('"');
        while (csv.readNext()) {
            if (palohelpers.StringToLong(csv.get(0)) == identifier) {
                plElm = new paloelement(this.plConn, this.lDatabaseId, this.iDimensionId, paloElements, palohelpers.StringToLong(csv.get(0)), csv.get(1), palohelpers.StringToInt(csv.get(2)), palohelpers.StringToInt(csv.get(3)), palohelpers.StringToInt(csv.get(4)), palohelpers.StringToInt(csv.get(5)), palohelpers.StringToInt(csv.get(6)), palohelpers.StringToInt(csv.get(7)), palohelpers.StringToIntArray(csv.get(8), palohelpers.StringToInt(csv.get(7))), palohelpers.StringToInt(csv.get(9)), palohelpers.StringToIntArray(csv.get(10), palohelpers.StringToInt(csv.get(9))), palohelpers.StringToDoubleArray(csv.get(11), palohelpers.StringToInt(csv.get(9))));
            }
        }
        csv.close();
        entity.consumeContent();
    } catch (Exception e) {
        throw new paloexception(e.getMessage());
    }
    return plElm;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 45 with HttpEntity

use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.

the class paloelement method updateElement.

public void updateElement(paloconsolidations plCons, boolean bAddToConsolidation) throws paloexception {
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("sid", this.plConn.getPaloToken()));
    qparams.add(new BasicNameValuePair("database", String.valueOf(lDatabaseId)));
    qparams.add(new BasicNameValuePair("dimension", String.valueOf(iDimensionId)));
    qparams.add(new BasicNameValuePair("element", String.valueOf(lElementIdentifier)));
    String strURLApiCall = "/element/append";
    if (!bAddToConsolidation) {
        if (plCons != null) {
            iElementType = paloelements.ELEMENT_CONSOLIDATION;
        }
        qparams.add(new BasicNameValuePair("name_element", strElementName));
        qparams.add(new BasicNameValuePair("type", String.valueOf(iElementType)));
        strURLApiCall = "/element/replace";
    }
    if (plCons != null) {
        qparams.add(new BasicNameValuePair("children", plCons.getConsolidationStringElementIdentifiers()));
        qparams.add(new BasicNameValuePair("weights", plCons.getConsolidationStringElementWeights()));
    }
    try {
        HttpEntity entity = this.plConn.sendToServer(qparams, strURLApiCall);
        CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
        csv.setQuoteChar('"');
        csv.readNext();
        // System.out.println(csv.getRawRecord());
        this.lElementIdentifier = palohelpers.StringToLong(csv.get(0));
        this.strElementName = csv.get(1);
        this.iElementPosition = palohelpers.StringToInt(csv.get(2));
        this.iElementLevel = palohelpers.StringToInt(csv.get(3));
        this.iElementIndent = palohelpers.StringToInt(csv.get(4));
        this.iElementDepth = palohelpers.StringToInt(csv.get(5));
        this.iElementType = palohelpers.StringToInt(csv.get(6));
        this.iElementNumOfParents = palohelpers.StringToInt(csv.get(7));
        this.iArrElementParents = palohelpers.StringToIntArray(csv.get(8), palohelpers.StringToInt(csv.get(7)));
        this.iElementNumOfChildren = palohelpers.StringToInt(csv.get(9));
        this.iArrElementChildren = palohelpers.StringToIntArray(csv.get(10), palohelpers.StringToInt(csv.get(9)));
        this.dArrElementChildrenWeights = palohelpers.StringToDoubleArray(csv.get(11), palohelpers.StringToInt(csv.get(9)));
        csv.close();
        entity.consumeContent();
    } catch (Exception e) {
        throw new paloexception(e.getMessage());
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Aggregations

HttpEntity (org.apache.http.HttpEntity)1391 HttpResponse (org.apache.http.HttpResponse)509 IOException (java.io.IOException)483 HttpGet (org.apache.http.client.methods.HttpGet)391 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)315 HttpPost (org.apache.http.client.methods.HttpPost)305 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)284 Test (org.junit.Test)259 ArrayList (java.util.ArrayList)248 HashMap (java.util.HashMap)177 MultipartEntityBuilder (org.apache.http.entity.mime.MultipartEntityBuilder)164 InputStream (java.io.InputStream)163 URI (java.net.URI)153 StatusLine (org.apache.http.StatusLine)149 StringEntity (org.apache.http.entity.StringEntity)148 Header (org.apache.http.Header)136 HttpClient (org.apache.http.client.HttpClient)127 VolleyError (com.android.volley.VolleyError)120 ApiException (io.swagger.client.ApiException)120 Pair (io.swagger.client.Pair)120