Search in sources :

Example 1 with ActivityItem

use of com.vodafone360.people.datatypes.ActivityItem in project 360-Engine-for-Android by 360.

the class DatabaseHelper method addActivities.

/**
     * Add a list of new activities to the Activities table.
     * 
     * @param activityList contains the list of activity item
     * @return SUCCESS or a suitable error code
     * @see #deleteActivities(Integer)
     */
public ServiceStatus addActivities(List<ActivityItem> activityList) {
    SQLiteDatabase writableDb = getWritableDatabase();
    ServiceStatus status = ActivitiesTable.addActivities(activityList, writableDb, mContext);
    ActivitiesTable.cleanupActivityTable(writableDb);
    fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, true);
    return status;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 2 with ActivityItem

use of com.vodafone360.people.datatypes.ActivityItem in project 360-Engine-for-Android by 360.

the class ActivitiesTable method fillUpdateData.

/***
     * Provides a ContentValues object that can be used to update the table.
     *
     * @param item The source activity item
     * @param contactIdx The index of the contact to use for the update, or null
     *            to exclude contact specific information.
     * @return ContentValues for use in an SQL update or insert.
     * @note Items that are NULL will be not modified in the database.
     */
private static ContentValues fillUpdateData(final ActivityItem item, final Integer contactIdx) {
    DatabaseHelper.trace(false, "DatabaseHelper.fillUpdateData()");
    ContentValues activityItemValues = new ContentValues();
    ActivityContact ac = null;
    if (contactIdx != null) {
        ac = item.contactList.get(contactIdx);
    }
    activityItemValues.put(Field.ACTIVITY_ID.toString(), item.activityId);
    activityItemValues.put(Field.TIMESTAMP.toString(), item.time);
    if (item.type != null) {
        activityItemValues.put(Field.TYPE.toString(), item.type.getTypeCode());
    }
    if (item.uri != null) {
        activityItemValues.put(Field.URI.toString(), item.uri);
    }
    /** TODO: Not sure if we need this. **/
    // activityItemValues.put(Field.INCOMING.toString(), false);
    activityItemValues.put(Field.TITLE.toString(), item.title);
    activityItemValues.put(Field.DESCRIPTION.toString(), item.description);
    if (item.previewUrl != null) {
        activityItemValues.put(Field.PREVIEW_URL.toString(), item.previewUrl);
    }
    if (item.store != null) {
        activityItemValues.put(Field.STORE.toString(), item.store);
    }
    if (item.activityFlags != null) {
        activityItemValues.put(Field.FLAG.toString(), item.activityFlags);
    }
    if (item.parentActivity != null) {
        activityItemValues.put(Field.PARENT_ACTIVITY.toString(), item.parentActivity);
    }
    if (item.hasChildren != null) {
        activityItemValues.put(Field.HAS_CHILDREN.toString(), item.hasChildren);
    }
    if (item.visibilityFlags != null) {
        activityItemValues.put(Field.VISIBILITY.toString(), item.visibilityFlags);
    }
    if (ac != null) {
        activityItemValues.put(Field.CONTACT_ID.toString(), ac.mContactId);
        activityItemValues.put(Field.USER_ID.toString(), ac.mUserId);
        activityItemValues.put(Field.CONTACT_NAME.toString(), ac.mName);
        activityItemValues.put(Field.LOCAL_CONTACT_ID.toString(), ac.mLocalContactId);
        if (ac.mNetwork != null) {
            activityItemValues.put(Field.CONTACT_NETWORK.toString(), ac.mNetwork);
        }
        if (ac.mAddress != null) {
            activityItemValues.put(Field.CONTACT_ADDRESS.toString(), ac.mAddress);
        }
        if (ac.mAvatarUrl != null) {
            activityItemValues.put(Field.CONTACT_AVATAR_URL.toString(), ac.mAvatarUrl);
        }
    }
    return activityItemValues;
}
Also used : ContentValues(android.content.ContentValues) ActivityContact(com.vodafone360.people.datatypes.ActivityContact)

Example 3 with ActivityItem

use of com.vodafone360.people.datatypes.ActivityItem in project 360-Engine-for-Android by 360.

the class ActivitiesEngineTest method reportBackToEngine.

@Override
public void reportBackToEngine(int reqId, EngineId engine) {
    Log.d("TAG", "IdentityEngineTest.reportBackToEngine");
    ResponseQueue respQueue = ResponseQueue.getInstance();
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    switch(mState) {
        case IDLE:
            break;
        case ON_CREATE:
        case ON_DESTROY:
            break;
        case GET_ACTIVITIES_SUCCESS:
            ActivityItem item = new ActivityItem();
            data.add(item);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_TIMELINE_EVENT_FROM_SERVER:
            ActivityItem item2 = new ActivityItem();
            ActivityContact act = new ActivityContact();
            act.mName = "Bill Fleege";
            act.mLocalContactId = new Long(8);
            List<ActivityContact> clist = new ArrayList<ActivityContact>();
            clist.add(act);
            item2.contactList = clist;
            item2.activityFlags = 2;
            item2.type = ActivityItem.Type.CONTACT_JOINED;
            item2.time = System.currentTimeMillis();
            data.add(item2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_POPULATED_ACTIVITIES:
            ActivityItem item3 = new ActivityItem();
            ActivityContact act2 = new ActivityContact();
            act2.mName = "Bill Fleege";
            act2.mLocalContactId = new Long(8);
            List<ActivityContact> clist2 = new ArrayList<ActivityContact>();
            clist2.add(act2);
            item3.contactList = clist2;
            item3.activityFlags = 2;
            item3.type = ActivityItem.Type.CONTACT_JOINED;
            item3.time = System.currentTimeMillis();
            item3.title = "bills new status";
            item3.description = "a description";
            data.add(item3);
            ActivityItem item4 = new ActivityItem();
            item4.contactList = clist2;
            item4.activityFlags = 5;
            item4.type = ActivityItem.Type.CONTACT_JOINED;
            item4.time = System.currentTimeMillis();
            item4.title = "bills new status";
            item4.description = "a description";
            item4.activityId = new Long(23);
            item4.hasChildren = false;
            item4.uri = "uri";
            item4.parentActivity = new Long(0);
            item4.preview = ByteBuffer.allocate(46);
            item4.preview.position(0);
            item4.preview.rewind();
            for (int i = 0; i < 23; i++) {
                item4.preview.putChar((char) i);
            }
            item4.previewMime = "jepg";
            item4.previewUrl = "storeurl";
            item4.store = "google";
            item4.visibilityFlags = 0;
            data.add(item4);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_ACTIVITIES_SERVER_ERR:
            ServerError err = new ServerError("Catastrophe");
            err.errorDescription = "Fail";
            data.add(err);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_ACTIVITIES_UNEXPECTED_RESPONSE:
            StatusMsg msg = new StatusMsg();
            msg.mCode = "ok";
            msg.mDryRun = false;
            msg.mStatus = true;
            data.add(msg);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.LOGIN_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case SET_STATUS:
            Identity id3 = new Identity();
            data.add(id3);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case ON_SYNC_COMPLETE:
            ServerError err2 = new ServerError("Catastrophe");
            err2.errorDescription = "Fail";
            data.add(err2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_NEXT_RUNTIME:
            break;
        default:
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) StatusMsg(com.vodafone360.people.datatypes.StatusMsg) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) ActivityContact(com.vodafone360.people.datatypes.ActivityContact) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue) Identity(com.vodafone360.people.datatypes.Identity) ActivityItem(com.vodafone360.people.datatypes.ActivityItem)

Example 4 with ActivityItem

use of com.vodafone360.people.datatypes.ActivityItem in project 360-Engine-for-Android by 360.

the class TestModule method createFakeActivitiesList.

/**
	 * TODO: fill in the method properly
	 * @return
	 */
public List<ActivityItem> createFakeActivitiesList() {
    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_FRIEND_INVITATION_SENT;
        /** 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.ALREADY_READ);
        /** 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;
}
Also used : ArrayList(java.util.ArrayList) Visibility(com.vodafone360.people.datatypes.ActivityItem.Visibility) Flag(com.vodafone360.people.datatypes.ActivityItem.Flag) ActivityItem(com.vodafone360.people.datatypes.ActivityItem)

Example 5 with ActivityItem

use of com.vodafone360.people.datatypes.ActivityItem in project 360-Engine-for-Android by 360.

the class NowPlusActivitiesTableTest method testFetchStatusEventList.

/**
	 * This method checks that status events are present in the table
	 */
public void testFetchStatusEventList() {
    Log.i(LOG_TAG, "***** testFetchStatusEventList: create table *****");
    SQLiteDatabase writableDataBase = mTestDatabase.getWritableDatabase();
    ActivitiesTable.create(writableDataBase);
    List<ActivityItem> activitiesList = mTestModule.createFakeStatusEventList();
    ServiceStatus status = ActivitiesTable.addActivities(activitiesList, writableDataBase, mContext);
    assertEquals("Activities not added to the table", ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "***** testFetchStatusEventList: activities added *****");
    // check if the records are there
    List<Long> activitiesIds = new ArrayList<Long>();
    for (ActivityItem item : activitiesList) {
        activitiesIds.add(item.activityId);
    }
    SQLiteDatabase readableDataBase = mTestDatabase.getReadableDatabase();
    List<Long> actualDBIds = new ArrayList<Long>();
    Cursor c = ActivitiesTable.fetchStatusEventList(YESTERDAY_TIME_MILLIS, readableDataBase);
    while (c.moveToNext()) {
        ActivityItem ai = new ActivityItem();
        ActivityContact ac = new ActivityContact();
        ActivitiesTable.getQueryData(c, ai, ac);
        if (ac.mContactId != null) {
            ai.contactList = new ArrayList<ActivityContact>();
            ai.contactList.add(ac);
        }
        actualDBIds.add(ai.activityId);
    }
    c.close();
    compareActivityIds(activitiesIds, actualDBIds);
    Log.i(LOG_TAG, "***** fetchStatusEventlist SUCCEEDED *****");
}
Also used : ActivityContact(com.vodafone360.people.datatypes.ActivityContact) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) ActivityItem(com.vodafone360.people.datatypes.ActivityItem)

Aggregations

ActivityItem (com.vodafone360.people.datatypes.ActivityItem)13 ArrayList (java.util.ArrayList)10 ServiceStatus (com.vodafone360.people.service.ServiceStatus)7 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)5 ActivityContact (com.vodafone360.people.datatypes.ActivityContact)5 Cursor (android.database.Cursor)3 MediumTest (android.test.suitebuilder.annotation.MediumTest)3 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)3 ContentValues (android.content.ContentValues)2 Flag (com.vodafone360.people.datatypes.ActivityItem.Flag)2 Visibility (com.vodafone360.people.datatypes.ActivityItem.Visibility)2 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)2 SQLException (android.database.SQLException)1 SQLiteStatement (android.database.sqlite.SQLiteStatement)1 Suppress (android.test.suitebuilder.annotation.Suppress)1 TimelineSummaryItem (com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem)1 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)1 Identity (com.vodafone360.people.datatypes.Identity)1 ServerError (com.vodafone360.people.datatypes.ServerError)1 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)1