Search in sources :

Example 46 with Request

use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.

the class SyncMeEngine method processSetMeResponse.

/**
 * Processes the response from a SetMe request. If successful, the server
 * IDs will be stored in the local database if they have changed. Otherwise
 * the processor will complete with a suitable error.
 * @param resp Response from server.
 */
private void processSetMeResponse(final DecodedResponse resp) {
    LogUtils.logD("SyncMeProfile.processMeProfileUpdateResponse()");
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactChanges result = (ContactChanges) resp.mDataTypes.get(0);
        SyncMeDbUtils.updateMeProfileDbDetailIds(mDbHelper, mUploadedMeDetails, result);
        if (updateRevisionPostUpdate(result.mServerRevisionBefore, result.mServerRevisionAfter, mFromRevision, mDbHelper)) {
            mFromRevision = result.mServerRevisionAfter;
        }
    }
    completeUiRequest(status);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ContactChanges(com.vodafone360.people.datatypes.ContactChanges)

Example 47 with Request

use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.

the class SyncMeEngine method uploadMeProfile.

/**
 * * Sends a SetMe request to the server in the case that the me profile has
 * been changed locally. If the me profile thumbnail has always been changed
 * it will also be uploaded to the server.
 */
private void uploadMeProfile() {
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        return;
    }
    newState(State.UPDATING_ME_PROFILE);
    Contact meProfile = new Contact();
    mDbHelper.fetchContact(SyncMeDbUtils.getMeProfileLocalContactId(mDbHelper), meProfile);
    mUploadedMeDetails = SyncMeDbUtils.saveContactDetailChanges(mDbHelper, meProfile);
    setReqId(Contacts.setMe(this, mUploadedMeDetails, meProfile.aboutMe, meProfile.gender));
}
Also used : Contact(com.vodafone360.people.datatypes.Contact)

Example 48 with Request

use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.

the class RequestQueue method clearActiveRequests.

/**
 * Return the current (i.e. most recently generated) request id.
 *
 * @return the current request id.
 */
/*
     * public synchronized int getCurrentId(){ return mCurrentRequestId; }
     */
/**
 * Clear active requests (i.e add dummy response to response queue).
 *
 * @param rpgOnly
 */
protected void clearActiveRequests(boolean rpgOnly) {
    synchronized (QueueManager.getInstance().lock) {
        ResponseQueue rQ = ResponseQueue.getInstance();
        for (int i = 0; i < mRequests.size(); i++) {
            Request request = mRequests.get(i);
            if (request.isActive() && (!rQ.responseExists(request.getRequestId()))) {
                if (!rpgOnly || (rpgOnly && ((request.getAuthenticationType() == Request.USE_RPG) || (request.getAuthenticationType() == Request.USE_BOTH)))) {
                    LogUtils.logE("RequestQueue.clearActiveRequests() Deleting request " + request.getRequestId());
                    mRequests.remove(i);
                    // necessarily times out before)
                    if (request.getExpiryDate() > 0) {
                        mTimeOutWatcher.removeRequest(request);
                    }
                    i--;
                    rQ.addToResponseQueue(new DecodedResponse(request.getRequestId(), null, request.mEngineId, DecodedResponse.ResponseType.TIMED_OUT_RESPONSE.ordinal()));
                }
            }
        }
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)

Example 49 with Request

use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.

the class ResponseQueue method addToResponseQueue.

/**
 * Adds a response item to the queue.
 *
 * @param reqId The request ID to add the response for.
 * @param data The response data to add to the queue.
 * @param source The corresponding engine that fired off the request for the
 *            response.
 */
public void addToResponseQueue(final DecodedResponse response) {
    synchronized (QueueManager.getInstance().lock) {
        ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.UNKNOWN_DATA_TYPE, response.mDataTypes);
        if (status == ServiceStatus.ERROR_INVALID_SESSION) {
            EngineManager em = EngineManager.getInstance();
            if (em != null) {
                LogUtils.logE("Logging out the current user because of invalide session");
                em.getLoginEngine().logoutAndRemoveUser();
                return;
            }
        }
        synchronized (mResponses) {
            mResponses.add(response);
        }
        Request request = RequestQueue.getInstance().removeRequest(response.mReqId);
        if (request != null) {
            // we suppose the response being handled by the same engine
            // that issued the request with the given id
            response.mSource = request.mEngineId;
        }
        mEngMgr = EngineManager.getInstance();
        if (mEngMgr != null) {
            mEngMgr.onCommsInMessage(response.mSource);
        }
    }
}
Also used : EngineManager(com.vodafone360.people.engine.EngineManager) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 50 with Request

use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.

the class NativeContactsApi2 method putOrganization.

// PHOTO NOT USED
// /**
// * Do a GET request and retrieve up to maxBytes bytes
// *
// * @param url
// * @param maxBytes
// * @return
// * @throws IOException
// */
// public static byte[] doGetAndReturnBytes(URL url, int maxBytes) throws
// IOException {
// HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// conn.setRequestMethod("GET");
// InputStream istr = null;
// try {
// int rc = conn.getResponseCode();
// if (rc != 200) {
// throw new IOException("code " + rc + " '" + conn.getResponseMessage() +
// "'");
// }
// istr = new BufferedInputStream(conn.getInputStream(), 512);
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// copy(istr, baos, maxBytes);
// return baos.toByteArray();
// } finally {
// if (istr != null) {
// istr.close();
// }
// }
// }
// 
// /**
// * Copy maxBytes from an input stream to an output stream.
// * @param in
// * @param out
// * @param maxBytes
// * @return
// * @throws IOException
// */
// private static int copy(InputStream in, OutputStream out, int maxBytes)
// throws IOException {
// byte[] buf = new byte[512];
// int bytesRead = 1;
// int totalBytes = 0;
// while (bytesRead > 0) {
// bytesRead = in.read(buf, 0, Math.min(512, maxBytes - totalBytes));
// if (bytesRead > 0) {
// out.write(buf, 0, bytesRead);
// totalBytes += bytesRead;
// }
// }
// return totalBytes;
// }
// 
// /**
// * Put Photo detail into the values
// * @param cc {@link ContactChange} to read values from
// */
// private void putPhoto(ContactChange cc) {
// try {
// // File file = new File(cc.getValue());
// // InputStream is = new FileInputStream(file);
// // byte[] bytes = new byte[(int) file.length()];
// // is.read(bytes);
// // is.close();
// final URL url = new URL(cc.getValue());
// byte[] bytes = doGetAndReturnBytes(url, 1024 * 100);
// mValues.put(Photo.PHOTO, bytes);
// mValues.put(Photo.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
// } catch(Exception ex) {
// LogUtils.logE("Unable to put Photo detail because of exception:"+ex);
// }
// }
/**
 * Put Organization detail into the values
 *
 * @param cc {@link ContactChange} to read values from
 */
private void putOrganization(ContactChange[] ccList) {
    mValues.clear();
    int flags = ContactChange.FLAG_NONE;
    if (mMarkedOrganizationIndex > -1) {
        final ContactChange cc = ccList[mMarkedOrganizationIndex];
        flags |= cc.getFlags();
        final Organisation organization = VCardHelper.getOrg(cc.getValue());
        if (organization != null) {
            mValues.put(Organization.COMPANY, organization.name);
            if (organization.unitNames.size() > 0) {
                // Only considering one unit name (department) as that's all
                // we support
                mValues.put(Organization.DEPARTMENT, organization.unitNames.get(0));
            } else {
                mValues.putNull(Organization.DEPARTMENT);
            }
        }
    }
    if (mMarkedTitleIndex > -1) {
        final ContactChange cc = ccList[mMarkedTitleIndex];
        flags |= cc.getFlags();
        // No need to check for empty values as there is only one
        mValues.put(Organization.TITLE, cc.getValue());
    }
    if (mValues.size() > 0) {
        mValues.put(Organization.LABEL, (String) null);
        mValues.put(Organization.TYPE, mapToNabOrganizationType(flags));
        mValues.put(Organization.IS_PRIMARY, flags & ContactChange.FLAG_PREFERRED);
        mValues.put(Organization.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
    }
}
Also used : Organisation(com.vodafone360.people.datatypes.VCardHelper.Organisation)

Aggregations

Request (com.vodafone360.people.service.io.Request)43 QueueManager (com.vodafone360.people.service.io.QueueManager)27 ServiceStatus (com.vodafone360.people.service.ServiceStatus)16 ArrayList (java.util.ArrayList)16 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)12 ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)12 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)11 Suppress (android.test.suitebuilder.annotation.Suppress)10 DatabaseHelper (com.vodafone360.people.database.DatabaseHelper)9 IEngineEventCallback (com.vodafone360.people.engine.IEngineEventCallback)9 IContactSyncCallback (com.vodafone360.people.engine.contactsync.IContactSyncCallback)9 ProcessorFactory (com.vodafone360.people.engine.contactsync.ProcessorFactory)9 ServerError (com.vodafone360.people.datatypes.ServerError)6 IOException (java.io.IOException)6 Identity (com.vodafone360.people.datatypes.Identity)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Bundle (android.os.Bundle)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)4 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)4 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)4