Java Code Examples for com.nextgis.maplib.util.AccountUtil#getAccountData()

The following examples show how to use com.nextgis.maplib.util.AccountUtil#getAccountData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected HttpResponse sendFeatureAttachOnServer(JSONObject result, long featureId, AttachItem attach) throws JSONException, IOException {
    // add attachment to row
    JSONObject postJsonData = new JSONObject();
    JSONArray uploadMetaArray = result.getJSONArray("upload_meta");
    postJsonData.put("file_upload", uploadMetaArray.get(0));
    postJsonData.put("description", attach.getDescription());
    String postload = postJsonData.toString();
    if (Constants.DEBUG_MODE) {
        Log.d(Constants.TAG, "postload: " + postload);
    }

    // get account data
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    // upload file
    String url = NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId);

    // update record in NGW
    return NetworkUtil.post(url, postload, accountData.login, accountData.password, false);
}
 
Example 2
Source File: NGWRasterLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Bitmap getBitmap(TileItem tile) {
    if (!mExtentReceived) {
        HttpResponse result = null;
        try {
            AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, getAccountName());
            result = NetworkUtil.get(NGWUtil.getExtent(accountData.url, mRemoteId), getLogin(), getPassword(), false);
            if (!result.isOk()) {
                throw new IllegalStateException("");
            }
            JSONObject extent = new JSONObject(result.getResponseBody()).getJSONObject(JSON_EXTENT_KEY);
            double x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MAX_LON_KEY));
            double y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MAX_LAT_KEY));
            mExtents.setMax(x, y);
            x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MIN_LON_KEY));
            y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MIN_LAT_KEY));
            mExtents.setMin(x, y);
            mExtentReceived = true;
        } catch (IOException | JSONException | IllegalStateException ignored) {
            if (result != null && result.getResponseCode() == 404)
                mExtentReceived = true;
        }
    }

    if (mExtents.intersects(tile.getEnvelope()))
        return super.getBitmap(tile);

    return null;
}
 
Example 3
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getRemoteUrl()
{
    try {
        AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);
        return NGWUtil.getResourceUrl(accountData.url, mRemoteId);
    } catch (IllegalStateException e) {
        return null;
    }
}
 
Example 4
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected HttpResponse sendAttachOnServer(long featureId, AttachItem attach) throws IOException {
    // fill attach info
    String fileName = attach.getDisplayName();
    File filePath = new File(mPath, featureId + File.separator + attach.getAttachId());
    String fileMime = attach.getMimetype();

    // get account data
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    // upload file
    String url = NGWUtil.getFileUploadUrl(accountData.url);
    return NetworkUtil.postFile(url, fileName, filePath, fileMime, accountData.login, accountData.password, false);
}
 
Example 5
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected HttpResponse changeFeatureOnServer(long featureId, String payload) throws IOException {
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    // change on server
    String url = NGWUtil.getFeatureUrl(accountData.url, mRemoteId, featureId);
    return NetworkUtil.put(url, payload, accountData.login, accountData.password, false);
}
 
Example 6
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected HttpResponse changeAttachOnServer(long featureId, long attachId, String putData) throws IOException {
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);
    String url = NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId) + attachId;
    return NetworkUtil.put(url, putData, accountData.login,
                                            accountData.password, false);
}
 
Example 7
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected HttpResponse deleteAttachOnServer(long featureId, long attachId) throws IOException {
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    return NetworkUtil.delete(NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId)
                    + attachId, accountData.login, accountData.password, false);
}
 
Example 8
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected HttpResponse addFeatureOnServer(String payload) throws IOException {
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    return NetworkUtil.post(NGWUtil.getFeaturesUrl(accountData.url, mRemoteId),
                     payload, accountData.login, accountData.password, false);
}
 
Example 9
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected HttpResponse deleteFeatureOnServer(long featureId) throws IOException {
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    return NetworkUtil.delete(NGWUtil.getFeatureUrl(accountData.url, mRemoteId, featureId),
                               accountData.login, accountData.password, false);
}