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);
}
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));
}
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()));
}
}
}
}
}
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);
}
}
}
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);
}
}
Aggregations