public void deleteEntity(EntityReference ref, Map<String, Object> params) { if (myEntities.remove(ref.getId()) == null) { throw new IllegalArgumentException("Invalid entity id, cannot find entity to remove: " + ref); } }
public void deleteEntity(EntityReference ref, Map<String, Object> params) { if (myEntities.remove(ref.getId()) == null) { throw new IllegalArgumentException("Invalid entity id, cannot find entity to remove: " + ref); } }
/** * @deprecated do not use this method anymore, use the constructors for {@link EntityReference} */ public static String getID(String reference) { return new EntityReference(reference).getId(); }
public String getToolIdFromToolRef(String toolReference) { String toolId = null; if (toolReference != null) { toolId = new EntityReference(toolReference).getId(); } return toolId; }
public String getLocationIdFromRef(String locationReference) { String locationId = null; if (locationReference != null) { // assume the form of "/site/siteId" (the Site method is protected) locationId = new EntityReference(locationReference).getId(); } return locationId; }
public Object getEntity(EntityReference ref) { long longId = 0; try{ longId = Long.valueOf(ref.getId()); }catch(NumberFormatException e){ return null; } return M_rm.getReportDefinition(longId); }
/** * Creates a copy of an entity reference * @param ref an entity reference object * @return the new copy of the ref * @throws IllegalArgumentException if the ref is invalid OR null */ public static EntityReference copy(EntityReference ref) { if (ref == null) { throw new IllegalArgumentException("input entity reference must not be null"); } EntityReference copy = new EntityReference(ref.getPrefix(), ref.getId() == null ? "" : ref.getId()); return copy; }
public String getUserIdFromRef(String userReference) { String userId = null; if (userReference != null) { if (userReference.startsWith("/")) { // assume the form of "/user/userId" (the UDS method is protected) userId = new EntityReference(userReference).getId(); } else { // otherwise assume this is the id userId = userReference; } } return userId; }
/** * Will convert a reference into an id (even if it is not a reference) * @param reference an entity reference (e.g. /user/aaronz) * @return the id from the reference (e.g. aaronz), preserves null */ public static String getIdFromRef(String reference) { String id = null; if (reference != null) { if (reference.startsWith("/")) { // assume the form of "/user/userId" id = new EntityReference(reference).getId(); } else { // otherwise assume this is the id id = reference; } } return id; }
public void deleteEntity(EntityReference ref, Map<String, Object> params) { String channelId = ref.getId(); ChatChannel channel = chatManager.getChatChannel(channelId); if (channel == null) { throw new IllegalStateException("The specified chat channel (" + channelId + ") does not exist"); } try { chatManager.deleteChannel(channel); } catch (PermissionException e) { throw new SecurityException("You do not have permission to delete this channel"); } return; } }
/** * Override this if you are making a new class to define your entity reference * * @param spaceOnly if this is true then only return the entity space reference (e.g. /prefix), * otherwise return the full reference (e.g. /prefix/id) * @return an entity reference string */ protected String makeEntityReference(boolean spaceOnly) { // OVERRIDE THIS when creating your own EntityReference if (getPrefix() == null) { throw new IllegalStateException("prefix is null, cannot generate the string reference"); } String ref = null; if (spaceOnly || getId() == null) { ref = SEPARATOR + getPrefix(); } else { ref = SEPARATOR + getPrefix() + SEPARATOR + getId(); } return ref; }
public Object getEntity(EntityReference ref) { String id = ref.getId(); if (id == null || "".equals(id)) { return new SimpleChatChannel(); } ChatChannel channel = chatManager.getChatChannel(id); if (channel == null) { throw new IllegalArgumentException("Channel not found"); } if (!chatManager.getCanReadMessage(channel)) { throw new SecurityException("You do not have permission to access this chat channel"); } return new SimpleChatChannel(channel); }
public Object getEntity(EntityReference ref) { String id = ref.getId(); if (id == null || "".equals(id)) { return new ChatMessage(); } ChatMessage msg = chatManager.getMessage(id); if (msg == null) { throw new IllegalArgumentException("Invalid message id"); } if (!chatManager.getCanReadMessage(msg.getChatChannel())) { throw new SecurityException( "You do not have permission to access this message"); } return new SimpleChatMessage(msg); }
/** * Expects {@link MyEntity} objects * {@inheritDoc} */ public void updateEntity(EntityReference ref, Object entity, Map<String, Object> params) { MyEntity me = (MyEntity) entity; if (me.getStuff() == null) { throw new IllegalArgumentException("stuff is not set, it is required"); } MyEntity current = myEntities.get(ref.getId()); if (current == null) { throw new IllegalArgumentException("Invalid update, cannot find entity"); } // update the fields current.setStuff( me.getStuff() ); current.setNumber( me.getNumber() ); current.extra = me.extra; }
public void updateEntity(EntityReference ref, Object entity, Map<String, Object> params) { String channelId = ref.getId(); SimpleChatChannel updchannel = (SimpleChatChannel) entity; ChatChannel channel = chatManager.getChatChannel(channelId); if (channel == null) { throw new IllegalStateException("The specified chat channel (" + channelId + ") does not exist"); } channel.setTitle(updchannel.getTitle()); channel.setDescription(updchannel.getDescription()); try { chatManager.updateChannel(channel, true); } catch (PermissionException e) { throw new SecurityException("You do not have permission to update this channel"); } }
public boolean parseEntityReference(String reference, Reference ref) { EntityReference entityref = null; try { entityref = entityBrokerManager.parseReference(reference); if (entityref == null) { return false; } } catch (Exception e) { return false; } // We will not attempt to check that the entity actually exists here, // only that the reference has a recognised prefix. EntityProvider entityProvider = entityProviderManager.getProviderByPrefix(entityref.prefix); if (entityProvider != null) { ref.set(entityref.getPrefix(), null, entityref.getId(), null, null); return true; } else { return false; } }