use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class HessianDecoder method decodeHessianByteArray.
/**
*
* Parse Hessian encoded byte array placing parsed contents into List.
*
* @param requestId The request ID that the response was received for.
* @param data byte array containing Hessian encoded data
* @param type Event type Shows whether we have a push or common message type.
* @param isZipped True if the response is gzipped, otherwise false.
* @param engineId The engine ID the response should be reported back to.
*
* @return The response containing the decoded objects.
*
* @throws IOException Thrown if there is something wrong with reading the (gzipped) hessian encoded input stream.
*
*/
public DecodedResponse decodeHessianByteArray(int requestId, byte[] data, Request.Type type, boolean isZipped, EngineId engineId) throws IOException {
InputStream is = null;
InputStream bis = null;
if (isZipped == true) {
LogUtils.logV("HessianDecoder.decodeHessianByteArray() Handle zipped data");
bis = new ByteArrayInputStream(data);
is = new GZIPInputStream(bis, data.length);
} else {
LogUtils.logV("HessianDecoder.decodeHessianByteArray() Handle non-zipped data");
is = new ByteArrayInputStream(data);
}
DecodedResponse response = null;
mMicroHessianInput.init(is);
LogUtils.logV("HessianDecoder.decodeHessianByteArray() Begin Hessian decode");
try {
response = decodeResponse(is, requestId, type, isZipped, engineId);
} catch (IOException e) {
LogUtils.logE("HessianDecoder.decodeHessianByteArray() " + "IOException during decodeResponse", e);
}
CloseUtils.close(bis);
CloseUtils.close(is);
return response;
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class TestModule method createFakeStatusEventList.
/**
* TODO: fill in the method properly
* @return
*/
public List<ActivityItem> createFakeStatusEventList() {
List<ActivityItem> activityList = new ArrayList<ActivityItem>();
for (int i = 0; i < TABLE_SIZE; i++) {
ActivityItem activityItem = new ActivityItem();
/** Unique identifier for the activity. This can be empty when setting
* a new activity (the id is generated on the server side) */
activityItem.activityId = System.currentTimeMillis();
/** Timestamp representing the time of the activity.
* This may not be related to creation/updated time. */
activityItem.time = System.currentTimeMillis();
/** local id for db */
// activityItem.mLocalId; set by DB insertion
// activityItem.mMoreInfo; //new Hashtable<ActivityItem, String>
/** The parent activity for 'grouped' or aggregated activities. This must be empty
* for normal activities that can be retrieved normally. Normally, a GetActivities
* without filter will not yield any 'grouped' or 'child' activities.
* To get activities that have a mParentActivity set, the 'children' filter must
* be used with a value of the parent Activity's id.*/
// activityItem.mParentActivity; // null
/** Indicates wether this activity 'groups' several child activities. When set,
* there must be child activities set that refer the main activity. Normally,
* a GetActivities without filter will not yield any 'grouped' or 'child' activities.
* To get activities that have a parentactivity set, the 'children' filter
* must be used with a value of the parent Activity's id.*/
// activityItem.mHasChildren = false;
/** Defines a binary preview for the activity. The preview can be a small thumbnail
* of the activity. The type of the binary data is defined into the previewmime field.*/
// keep null
// activityItem.mPreview = ByteBuffer.allocate(bytes.length);
// activityItem.mPreviewMime;
/** Defines an http url that the client can use to retrieve preview binary data.
* Can be used to embed the url into an IMG HTML tag.*/
// activityItem.mPreviewUrl
/** Name of the store type for this message. This field contains information about the
* originator network (local or external community activity).
* By default, should be set to local*/
activityItem.store = "local";
activityItem.title = generateRandomString();
activityItem.description = activityItem.description + activityItem.store;
/** Defines the type of the activity. */
activityItem.type = Type.CONTACT_RECEIVED_STATUS_UPDATE;
/** Defines an internal reference (if any) to the source of the activity.
* The format for the uri is "module:identifier".Some examples of valid uri are:
* contact:2737b322c9f6476ca152aa6cf3e5ac12 The activity is linked to some
* changes on a contact identified by id=2737b322c9f6476ca152aa6cf3e5ac12.
* file:virtual/flickr/2590004126 The activity is linked to some actions
* on a file identified by id=virtual/flickr/2590004126.
* message:9efd255359074dd9bd04cc1c8c4743e5 The activity is linked to a message
* identified by id=9efd255359074dd9bd04cc1c8c4743e5 */
activityItem.uri = "virtual/flickr/2590004126";
//can be 0 activityItem.mActivityFlags;
/** Miscellaneous flags.*/
activityItem.flagList = new ArrayList<Flag>();
activityItem.flagList.add(Flag.STATUS);
activityItem.activityFlags = 0x04;
/** Defines the contact information of the counter-parties in the activity.
* This field is not mandatory, because some activity types
* are not related to contacts, but required if known.. */
//keep it simple - empty activityItem.mContactList = ;
activityItem.visibility = new ArrayList<Visibility>();
activityItem.visibility.add(Visibility.ORIGINATOR);
//keep it 0 activityItem.mVisibilityFlags = 0;
activityList.add(activityItem);
}
return activityList;
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class ActivitiesEngine method handleGetActivitiesResponse.
/**
* Handle GetActivities response message received from Server
*
* @param reqId Request ID contained in response. This should match an ID of
* a request we have issued to the Server.
* @param data List array of ActivityItem items returned from Server.
*/
private void handleGetActivitiesResponse(List<BaseDataType> data) {
/** Array of Activities retrieved from Server. */
ArrayList<ActivityItem> activityList = new ArrayList<ActivityItem>();
ServiceStatus errorStatus = getResponseStatus(BaseDataType.ACTIVITY_ITEM_DATA_TYPE, data);
LogUtils.logE("ActivityEngine.handleGetActivitiesResponse status from generic = " + errorStatus);
if (ServiceStatus.SUCCESS == errorStatus) {
for (BaseDataType item : data) {
if (item.getType() == BaseDataType.ACTIVITY_ITEM_DATA_TYPE) {
activityList.add((ActivityItem) item);
} else {
LogUtils.logE("ActivityEngine.handleGetActivitiesResponse will not handle strange type = " + item.getType());
}
}
errorStatus = updateDatabase(activityList);
// we set timeout for the next execution
}
// this method will then call completeUiRequest(status, null);
onSyncHelperComplete(errorStatus);
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class NativeContactsApi1 method updateOrganization.
/**
* Updates the Organization detail in the context of a Contact Update
* operation. The end of result of this is that the Organization may be
* inserted, updated or deleted depending on the update data. For example,
* if the title is deleted but there is also a company name then the
* Organization is just updated. However, if there was no company name then
* the detail should be deleted altogether.
*
* @param ccList {@link ContactChange} list where Organization and Title may
* be found
* @param nabContactId The NAB ID of the Contact
* @return In the Organization insertion case this should contain the new ID
* and in the update case should contain the existing ID
*/
private long updateOrganization(ContactChange[] ccList, long nabContactId) {
if (mMarkedOrganizationIndex < 0 && mMarkedTitleIndex < 0) {
// no organization or title to update - do nothing
return ContactChange.INVALID_ID;
}
long detailId = ContactChange.INVALID_ID;
int flags = ContactChange.FLAG_NONE;
String company = null;
String title = null;
final Uri organizationUri = Uri.withAppendedPath(ContentUris.withAppendedId(People.CONTENT_URI, nabContactId), Contacts.Organizations.CONTENT_DIRECTORY);
final Cursor cursor = mCr.query(organizationUri, null, null, null, Organizations._ID);
// assuming that the lowest id is the one in CAB
try {
if (cursor != null && cursor.moveToNext()) {
company = CursorUtils.getString(cursor, Organizations.COMPANY);
title = CursorUtils.getString(cursor, Organizations.TITLE);
detailId = CursorUtils.getLong(cursor, Organizations._ID);
flags = mapFromNabOrganizationType(CursorUtils.getInt(cursor, Organizations.TYPE));
final boolean isPrimary = CursorUtils.getInt(cursor, Organizations.ISPRIMARY) > 0;
if (isPrimary) {
flags |= ContactChange.FLAG_PREFERRED;
}
}
} finally {
CursorUtils.closeCursor(cursor);
}
if (mMarkedOrganizationIndex >= 0) {
final ContactChange cc = ccList[mMarkedOrganizationIndex];
if (cc.getType() != ContactChange.TYPE_DELETE_DETAIL) {
final String value = cc.getValue();
if (value != null) {
final VCardHelper.Organisation organization = VCardHelper.getOrg(value);
if (!TextUtils.isEmpty(organization.name)) {
company = organization.name;
}
}
flags = cc.getFlags();
} else {
// Delete case
company = null;
}
}
if (mMarkedTitleIndex >= 0) {
final ContactChange cc = ccList[mMarkedTitleIndex];
title = cc.getValue();
if (cc.getType() != ContactChange.TYPE_DELETE_DETAIL) {
flags = cc.getFlags();
}
}
if (company != null || title != null) {
mValues.clear();
/*
* Forcing the label field to be null because we don't support
* custom labels and in case we replace from a custom label to home
* or private type without setting label to null, mCr.update() will
* throw a SQL constraint exception.
*/
mValues.put(Organizations.LABEL, (String) null);
mValues.put(Organizations.COMPANY, company);
mValues.put(Organizations.TITLE, title);
mValues.put(Organizations.TYPE, mapToNabOrganizationType(flags));
mValues.put(Organizations.ISPRIMARY, flags & ContactChange.FLAG_PREFERRED);
final Uri existingUri = ContentUris.withAppendedId(Contacts.Organizations.CONTENT_URI, detailId);
if (detailId != ContactChange.INVALID_ID) {
mCr.update(existingUri, mValues, null, null);
} else {
// insert
final Uri idUri = mCr.insert(organizationUri, mValues);
if (idUri != null) {
return ContentUris.parseId(idUri);
}
}
} else if (detailId != ContactChange.INVALID_ID) {
final Uri existingUri = ContentUris.withAppendedId(Contacts.Organizations.CONTENT_URI, detailId);
mCr.delete(existingUri, null, null);
} else {
mMarkedOrganizationIndex = mMarkedTitleIndex = -1;
}
// Updated detail id or ContactChange.INVALID_ID if deleted
return detailId;
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class NativeContactsApi2 method readAddress.
/**
* Reads an address detail as a {@link ContactChange} from the provided
* cursor. For this type of detail we need to use a VCARD (semicolon
* separated) value.
*
* @param cursor Cursor to read from
* @param ccList List of Contact Changes to add read detail data
* @param nabContactId ID of the NAB Contact
*/
private void readAddress(Cursor cursor, List<ContactChange> ccList, long nabContactId) {
// Using formatted address only to check if there is a valid address to
// read
final String formattedAddress = CursorUtils.getString(cursor, StructuredPostal.FORMATTED_ADDRESS);
if (!TextUtils.isEmpty(formattedAddress)) {
final long nabDetailId = CursorUtils.getLong(cursor, StructuredPostal._ID);
final int type = CursorUtils.getInt(cursor, StructuredPostal.TYPE);
int flags = mapFromNabAddressType(type);
final boolean isPrimary = CursorUtils.getInt(cursor, StructuredPostal.IS_PRIMARY) != 0;
if (isPrimary) {
flags |= ContactChange.FLAG_PREFERRED;
}
// VCard Helper data type (CAB)
final PostalAddress address = new PostalAddress();
// NAB: Street -> CAB: AddressLine1
address.addressLine1 = CursorUtils.getString(cursor, StructuredPostal.STREET);
// NAB: PO Box -> CAB: postOfficeBox
address.postOfficeBox = CursorUtils.getString(cursor, StructuredPostal.POBOX);
// NAB: Neighborhood -> CAB: AddressLine2
address.addressLine2 = CursorUtils.getString(cursor, StructuredPostal.NEIGHBORHOOD);
// NAB: City -> CAB: City
address.city = CursorUtils.getString(cursor, StructuredPostal.CITY);
// NAB: Region -> CAB: County
address.county = CursorUtils.getString(cursor, StructuredPostal.REGION);
// NAB: Post code -> CAB: Post code
address.postCode = CursorUtils.getString(cursor, StructuredPostal.POSTCODE);
// NAB: Country -> CAB: Country
address.country = CursorUtils.getString(cursor, StructuredPostal.COUNTRY);
final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_ADDRESS, VCardHelper.makePostalAddress(address), flags);
cc.setNabContactId(nabContactId);
cc.setNabDetailId(nabDetailId);
ccList.add(cc);
}
}
Aggregations