Android Open Source - Android-App-Project___Stay-Anonymous Cloud Entity






From Project

Back to project page Android-App-Project___Stay-Anonymous.

License

The source code is released under:

Apache License

If you think the Android project Android-App-Project___Stay-Anonymous listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (c) 2013 Google Inc.//w w w .j  a  v a  2  s.c o m
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.cloud.backend.core;

import com.google.api.client.util.DateTime;
import com.google.cloud.backend.android.mobilebackend.model.EntityDto;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * A class that represents a cloud entity on App Engine Datastore.
 */
public class CloudEntity {

    /**
     * Name of the auto-generated property that has a time stamp of creation.
     */
    public static final String PROP_CREATED_AT = "_createdAt";

    /**
     * Name of the auto-generated property that has a time stamp of update.
     */
    public static final String PROP_UPDATED_AT = "_updatedAt";

    /**
     * Name of the auto-generated property that has creator account name.
     */
    public static final String PROP_CREATED_BY = "_createdBy";

    /**
     * Name of the auto-generated property that has updater account name.
     */
    public static final String PROP_UPDATED_BY = "_updatedBy";

    /**
     * Name of the auto-generated property that has userId of the entity owner.
     */
    public static final String PROP_OWNER = "_owner";

    private String id;

    private Date createdAt;

    private Date updatedAt;

    private String createdBy;

    private String updatedBy;

    private String kindName;

    private Map<String, Object> properties = new HashMap<String, Object>();

    private String owner;

    @SuppressWarnings("unchecked")
    protected static CloudEntity createCloudEntityFromEntityDto(EntityDto cd) {
        CloudEntity co = new CloudEntity(cd.getKindName());
        co.id = cd.getId();
        co.createdAt = new Date(cd.getCreatedAt().getValue());
        co.updatedAt = new Date(cd.getUpdatedAt().getValue());
        co.createdBy = cd.getCreatedBy();
        co.updatedBy = cd.getUpdatedBy();
        co.kindName = cd.getKindName();
        co.properties.putAll((Map<String, Object>) cd.getProperties());
        co.owner = cd.getOwner();
        return co;
    }

    public CloudEntity(String kindName) {
        if (kindName == null || !kindName.matches("\\w+")) {
            throw new IllegalArgumentException("Illegal kind name: " + kindName);
        }
        this.kindName = kindName;
    }

    protected EntityDto getEntityDto() {
        EntityDto co = new EntityDto();
        co.setId(id);
        if (createdAt != null) {
            co.setCreatedAt(new DateTime(createdAt));
        }
        co.setCreatedBy(createdBy);
        co.setKindName(kindName);
        if (updatedAt != null) {
            co.setUpdatedAt(new DateTime(updatedAt));
        }
        co.setUpdatedBy(updatedBy);
        co.setProperties(properties);
        co.setOwner(owner);
        return co;
    }

    public void put(String key, Object value) {
        properties.put(key, value);
    }

    public Object get(String key) {
        return properties.get(key);
    }

    public Object remove(String key) {
        return properties.remove(key);
    }

    public Map<String, Object> getProperties() {
        return properties;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public String getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(String updatedBy) {
        this.updatedBy = updatedBy;
    }

    public String getKindName() {
        return kindName;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String aclOwner) {
        this.owner = aclOwner;
    }

    @Override
    public String toString() {
        return "CloudEntity(" + this.getKindName() + "/" + this.getId() + "): " + properties;
    }

    @Override
    public int hashCode() {
        String s = "" + this.id + this.kindName + this.createdAt + this.createdBy + this.updatedAt
                + this.updatedBy + this.owner + this.properties.hashCode();
        return s.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return obj.hashCode() == this.hashCode();
    }

}




Java Source Code List

com.google.cloud.backend.GCMBroadcastReceiver.java
com.google.cloud.backend.GCMIntentService.java
com.google.cloud.backend.android.mobilebackend.MobilebackendRequestInitializer.java
com.google.cloud.backend.android.mobilebackend.MobilebackendRequest.java
com.google.cloud.backend.android.mobilebackend.Mobilebackend.java
com.google.cloud.backend.android.mobilebackend.model.BlobAccess.java
com.google.cloud.backend.android.mobilebackend.model.EntityDto.java
com.google.cloud.backend.android.mobilebackend.model.EntityListDto.java
com.google.cloud.backend.android.mobilebackend.model.FilterDto.java
com.google.cloud.backend.android.mobilebackend.model.Filter.java
com.google.cloud.backend.android.mobilebackend.model.QueryDto.java
com.google.cloud.backend.core.CloudBackendAsync.java
com.google.cloud.backend.core.CloudBackendFragment.java
com.google.cloud.backend.core.CloudBackendMessaging.java
com.google.cloud.backend.core.CloudBackend.java
com.google.cloud.backend.core.CloudCallbackHandler.java
com.google.cloud.backend.core.CloudEndpointUtils.java
com.google.cloud.backend.core.CloudEntity.java
com.google.cloud.backend.core.CloudQuery.java
com.google.cloud.backend.core.Consts.java
com.google.cloud.backend.core.Filter.java
mobile_final.ChattingRoomActivity.java
mobile_final.EventListAdaptor.java
mobile_final.PostAdapter.java
mobile_final.SecondActivity.java
mobile_final.SplashFragment.java
mobile_final.StartingActivity.java
mobile_final.TestActivity.java
mobile_final.VoteHandler.java