/** * A string which is suitable for display and provides a short summary of the entity, * typically 100 chars or less, this may be the name or title of the data represented by an entity */ public String getDisplayTitle() { if (this.entityDisplayTitle == null) { if (this.entityRef != null) { return this.entityRef.getPrefix() + " : " + entityReference; } else { return "data"; } } return entityDisplayTitle; } private transient boolean displayTitleSet = false; // needed to avoid encoding
/** * 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 ViewParameters getViewParameters() { String requestref = reference.get(); EntityViewParamsInferrer evpi = null; if (!(requestref.equals(""))) { String prefix = EntityReference.getPrefix(requestref); evpi = (EntityViewParamsInferrer) inferrermap.get(prefix); } return evpi == null ? null : evpi.inferDefaultViewParameters(requestref); } }
public ViewParameters getViewParameters() { String requestref = reference.get(); EntityViewParamsInferrer evpi = null; if (!(requestref.equals(""))) { String prefix = EntityReference.getPrefix(requestref); evpi = (EntityViewParamsInferrer) inferrermap.get(prefix); } return evpi == null? null : evpi.inferDefaultViewParameters(requestref); } }
/** * @param ev the entity view * @param customAction the custom action * @return a URL for triggering the custom action (without http://server/direct) */ protected String makeActionURL(EntityView ev, CustomAction customAction) { // switched to this since it is more correct String URL = EntityView.SEPARATOR + ev.getEntityReference().getPrefix() + EntityView.SEPARATOR + customAction.action; String viewKey = customAction.viewKey; if (viewKey != null && (EntityView.VIEW_SHOW.equals(viewKey) || EntityView.VIEW_EDIT.equals(viewKey) || EntityView.VIEW_DELETE.equals(viewKey))) { URL = ev.getEntityURL(EntityView.VIEW_SHOW, null) + EntityView.SEPARATOR + customAction.action; } return URL; }
/** * @param ev the entity view * @param customAction the custom action * @return a URL for triggering the custom action (without http://server/direct) */ protected String makeActionURL(EntityView ev, CustomAction customAction) { // switched to this since it is more correct String URL = EntityView.SEPARATOR + ev.getEntityReference().getPrefix() + EntityView.SEPARATOR + customAction.action; String viewKey = customAction.viewKey; if (viewKey != null && (EntityView.VIEW_SHOW.equals(viewKey) || EntityView.VIEW_EDIT.equals(viewKey) || EntityView.VIEW_DELETE.equals(viewKey))) { URL = ev.getEntityURL(EntityView.VIEW_SHOW, null) + EntityView.SEPARATOR + customAction.action; } return URL; }
/** * Get the entity without a change (may be EntityData or just an object) */ protected Object fetchEntityObject(EntityReference ref) { Object entity = null; Resolvable provider = entityProviderManager.getProviderByPrefixAndCapability(ref.getPrefix(), Resolvable.class); if (provider != null) { entity = provider.getEntity(ref); } return entity; }
/** * 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; }
if (entityProviderManager.getProviderByPrefixAndCapability(ref.getPrefix(), Taggable.class) != null) { TagProvideable provider = entityProviderManager.getProviderByPrefixAndCapability(ref.getPrefix(), TagProvideable.class); if (provider == null) { newTagApps.add( new EntityTagApplication(reference, ref.getPrefix(), tag) );
this.pathSegments = new HashMap<String, String>(); this.pathSegments.put(PREFIX, ref.getPrefix()); if (ref.getId() != null) { this.pathSegments.put(ID, ref.getId());
public void removeTagsFromEntity(String reference, String[] tags) { if (tags == null) { throw new IllegalArgumentException("Invalid params, tags cannot be null"); } validateTags(tags); // ensures tags are valid EntityReference ref = entityBrokerManager.parseReference(reference); if (ref == null) { throw new IllegalArgumentException("Invalid reference (" + reference + "), no entity provider to handle this reference"); } else { reference = ref.toString(); if (! entityBrokerManager.entityExists(ref)) { throw new IllegalArgumentException("Invalid reference (" + reference + "), entity does not exist"); } if (entityProviderManager.getProviderByPrefixAndCapability(ref.getPrefix(), Taggable.class) != null) { TagProvideable provider = entityProviderManager.getProviderByPrefixAndCapability(ref.getPrefix(), TagProvideable.class); if (provider == null) { // put in call to central tag system here if desired dao.deleteTags(reference, tags); } else { provider.removeTagsFromEntity(reference, tags); } } else { throw new UnsupportedOperationException("Cannot set tags for this entity ("+reference+"), it has no support for tagging in its entity provider"); } } }
public String getPropertyValue(String reference, String name) { if (name == null || "".equals(name)) { throw new IllegalArgumentException("Invalid name argument, name must not be null or empty"); } String value = null; EntityReference ref = entityBrokerManager.parseReference(reference); if (ref != null) { if (! entityBrokerManager.entityExists(ref)) { throw new IllegalArgumentException("Invalid reference (" + reference + "), entity does not exist"); } PropertyProvideable provider = entityProviderManager.getProviderByPrefixAndCapability(ref.getPrefix(), PropertyProvideable.class); if (provider != null) { value = provider.getPropertyValue(reference, name); } else { List<EntityProperty> properties = dao.findBySearch(EntityProperty.class, new Search( new String[] { "entityRef", "propertyName" }, new Object[] { reference, name } ) ); if (properties.size() > 0) { value = properties.get(0).getPropertyValue(); } } } return value; }
setEntityReference(ref); this.pathSegments = new HashMap<String, String>(); this.pathSegments.put(PREFIX, ref.getPrefix()); if (viewKey == null) { if (this.entityReference.getId() == null) {
public Map<String, String> getProperties(String reference) { Map<String, String> m = new HashMap<String, String>(); EntityReference ref = entityBrokerManager.parseReference(reference); if (ref != null) { if (! entityBrokerManager.entityExists(ref)) { throw new IllegalArgumentException("Invalid reference (" + reference + "), entity does not exist"); } PropertyProvideable provider = entityProviderManager.getProviderByPrefixAndCapability(ref.getPrefix(), PropertyProvideable.class); if (provider != null) { Map<String, String> epMap = provider.getProperties(reference); if (epMap != null) { m.putAll( epMap ); } } else { List<EntityProperty> properties = dao.findBySearch(EntityProperty.class, new Search( "entityRef", reference ) ); for (EntityProperty property : properties) { m.put(property.getPropertyName(), property.getPropertyValue()); } } } return m; }
throw new IllegalArgumentException("Invalid entity reference, no provider found to handle this ref: " + reference); ActionsExecutable actionProvider = entityProviderManager.getProviderByPrefixAndCapability(ref.getPrefix(), ActionsExecutable.class); if (actionProvider == null) { throw new IllegalArgumentException("The provider for prefix ("+ref.getPrefix()+") cannot handle custom actions");
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; } }
/** * Determines if an entity exists based on the reference * * @param reference an entity reference object * @return true if entity exists, false otherwise */ public boolean entityExists(EntityReference ref) { boolean exists = false; if (ref != null) { EntityProvider provider = entityProviderManager.getProviderByPrefix(ref.getPrefix()); if (provider == null) { // no provider found so no entity can't exist exists = false; } else if (!(provider instanceof CoreEntityProvider)) { // no core provider so assume it does exist exists = true; } else { if (ref.getId() == null) { // currently we assume exists if it is only a prefix exists = true; } else { exists = ((CoreEntityProvider) provider).entityExists( ref.getId() ); } } } return exists; }
/** * Reduce code duplication and ensure custom templates are used */ public EntityView makeEntityView(EntityReference ref, String viewKey, String extension) { if (ref == null) { throw new IllegalArgumentException("ref cannot be null"); } EntityView view = new EntityView(); EntityViewUrlCustomizable custom = (EntityViewUrlCustomizable) entityProviderManager .getProviderByPrefixAndCapability(ref.getPrefix(), EntityViewUrlCustomizable.class); if (custom != null) { // use the custom parsing templates view.loadParseTemplates( custom.getParseTemplates() ); } view.setEntityReference(ref); if (viewKey != null) { view.setViewKey(viewKey); } if (extension != null) { view.setExtension(extension); } return view; }
/** * Makes a copy of an EntityView which can be changed independently * @param ev any EntityView * @return the copy * @throws IllegalArgumentException if the input is null OR not completely constructed */ public static EntityView copy(EntityView ev) { if (ev == null) { throw new IllegalArgumentException("input entity view must not be null"); } if (ev.viewKey == null || ev.entityReference == null) { throw new IllegalArgumentException("input entity view must be completely constructed"); } EntityView togo = new EntityView(); EntityReference ref = ev.getEntityReference(); togo.setEntityReference( new EntityReference(ref.getPrefix(), ref.getId() == null ? "" : ref.getId()) ); togo.preloadParseTemplates( ev.getAnazlyzedTemplates() ); togo.setExtension( ev.getExtension() ); togo.setViewKey( ev.getViewKey() ); return togo; }