Java tutorial
/* * EYWA.COM (Eywa Commerce) * This program is an integrated platform with E-Commerce and Configurator system. * Support: Please, contact the Author on http://www.smartfeeling.org. * Copyright (C) 2014 Gian Angelo Geminiani * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.eywa.impl.app.mongo.entities.items.jobs.filesharing; import com.eywa.impl.app.IAppConstants; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; import org.ly.commons.util.StringUtils; import org.ly.packages.mongo.impl.util.MongoUtils; import java.util.Collection; import java.util.List; /** * Item for Scheduler DATA field. * Contains information about File Sharing job */ public class ItemJobFileSharing extends BasicDBObject { public static final String TYPE_ADD_SHARE = "job-add-share"; public static final String TYPE_REMOVE_SHARE = "job-remove-share"; // ------------------------------------------------------------------------ // f i e l d s // ------------------------------------------------------------------------ public static final String TYPE = IAppConstants.TYPE; // data type public static final String USER_ID = IAppConstants.USER_ID; // who is sharing? public static final String ENTITY_COLLECTION = IAppConstants.ENTITY_COLLECTION; // is sharing connected to a post, a document? public static final String ENTITY_ID = IAppConstants.ENTITY_ID; // is sharing connected to a post, a document? public static final String FILES = IAppConstants.FILES; // list of file ID public static final String USERS = IAppConstants.USERS; // list of user ID (recipient) // ------------------------------------------------------------------------ // c o n s t r u c t o r // ------------------------------------------------------------------------ public ItemJobFileSharing(final String type) { MongoUtils.put(this, TYPE, type); } public ItemJobFileSharing() { MongoUtils.put(this, TYPE, TYPE_ADD_SHARE); } // ------------------------------------------------------------------------ // p r i v a t e // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ // S T A T I C // ------------------------------------------------------------------------ public static boolean isAddShare(final DBObject item) { return isAddShare(getType(item)); } public static boolean isAddShare(final String type) { return StringUtils.hasText(type) && type.equalsIgnoreCase(TYPE_ADD_SHARE); } public static boolean isRemoveShare(final DBObject item) { return isRemoveShare(getType(item)); } public static boolean isRemoveShare(final String type) { return StringUtils.hasText(type) && type.equalsIgnoreCase(TYPE_REMOVE_SHARE); } public static String getType(final DBObject item) { return MongoUtils.getString(item, TYPE); } public static void setType(final DBObject item, final String value) { MongoUtils.put(item, TYPE, value); } public static String getUserId(final DBObject item) { return MongoUtils.getString(item, USER_ID); } public static void setUserId(final DBObject item, final String value) { MongoUtils.put(item, USER_ID, value); } public static String getEntityCollection(final DBObject item) { return MongoUtils.getString(item, ENTITY_COLLECTION); } public static void setEntityCollection(final DBObject item, final String value) { MongoUtils.put(item, ENTITY_COLLECTION, value); } public static String getEntityId(final DBObject item) { return MongoUtils.getString(item, ENTITY_ID); } public static void setEntityId(final DBObject item, final String value) { MongoUtils.put(item, ENTITY_ID, value); } public static List<String> getFiles(final DBObject item) { return MongoUtils.getList(item, FILES); } public static void setFiles(final DBObject item, final Collection<String> value) { MongoUtils.put(item, FILES, value); } public static List<String> getUsers(final DBObject item) { return MongoUtils.getList(item, USERS); } public static void setUsers(final DBObject item, final Collection<String> value) { MongoUtils.put(item, USERS, value); } }