/** * Special constructor which will ensure the data is output exactly as is without adding in the entity meta data * @param data the data to encode (any java objects including collections, POJOs, maps, etc.) * @param headers (optional) headers to include in the response (can use the header constants if desired: {@link Header}) * @param format (optional) the format to return this data in (from {@link Formats}), e.g. Formats.XML */ public ActionReturn(Object data, Map<String, String> headers, String format) { if (data != null && EntityData.class.isAssignableFrom(data.getClass())) { this.entityData = (EntityData) data; } else { this.entityData = new EntityData(data); } this.format = format; setHeaders(headers); }
if (entityData.isPopulated() || entityData.isDataOnly()) { continue; } else { entityData.setPopulated(true); EntityReference ref = entityData.getEntityRef(); EntityView view = null; if (views.containsKey(ref.getPrefix())) { String partialURL = view.getEntityURL(); String fullURL = makeFullURL( partialURL ); entityData.setEntityURL( fullURL ); if (entityData.getData() != null) { if ( ConstructorUtils.isClassBean(entityData.getData().getClass()) ) { isPOJO = true; if (! entityData.isDisplayTitleSet()) { boolean titleNotSet = true; if (entityData.getEntityProperties() != null) { String title = EntityDataUtils.findMapStringValue(entityData.getEntityProperties(), new String[] {"displayTitle","title","displayName","name"}); if (title != null) { entityData.setDisplayTitle(title); titleNotSet = false; String title = ReflectUtils.getInstance().getFieldValueAsString(entityData.getData(), "title", EntityTitle.class); if (title != null) { entityData.setDisplayTitle(title);
public int compare(EntityData o1, EntityData o2) { return o1.getDisplayTitle().compareTo(o2.getDisplayTitle()); } }
/** * Using this as a data wrapper only * @param data any data to wrap this in * @param entityProperties a set of properties to return along with the entity information, * this may be presented and used for filtering, */ public EntityData(Object data, Map<String, Object> entityProperties) { setData(data); setEntityProperties(entityProperties); this.dataOnly = true; }
// EntityFactory public static Entity createById(ResultSet resultSet) { EntityData data = new EntityData(25); for (int sample = 1; sample <= 25; sample++) { String sample_R = new StringBuilder("sample_").append(sample).append("_R").toString(); String sample_G = new StringBuilder("sample_").append(sample).append("_G").toString(); String sample_B = new StringBuilder("sample_").append(sample).append("_B").toString(); int r = resultSet.getInt(sample_R); int g = resultSet.getInt(sample_G); int b = resultSet.getInt(sample_B); data.add(r, g, b); } return new Entity(data); }
sb.append("NO DATA to encode"); } else { sb.append(" <div style='font-weight:bold;'>"+StringEscapeUtils.escapeHtml(entityData.getDisplayTitle())+"</div>\n"); sb.append(" <table border='1'>\n"); sb.append(" <caption style='font-weight:bold;'>Entity Data</caption>\n"); if (! entityData.isDataOnly()) { sb.append(" <tr><td>entityReference</td><td>"+StringEscapeUtils.escapeHtml(entityData.getEntityReference())+"</td></tr>\n"); sb.append(" <tr><td>entityURL</td><td>"+StringEscapeUtils.escapeHtml(entityData.getEntityURL())+"</td></tr>\n"); if (entityData.getEntityRef() != null) { sb.append(" <tr><td>entityPrefix</td><td>"+StringEscapeUtils.escapeHtml(entityData.getEntityRef().getPrefix())+"</td></tr>\n"); if (entityData.getEntityRef().getId() != null) { sb.append(" <tr><td>entityID</td><td>"+StringEscapeUtils.escapeHtml(entityData.getEntityRef().getId())+"</td></tr>\n"); if (entityData.getData() != null) { sb.append(" <tr><td>entity-type</td><td>"+entityData.getData().getClass().getName()+"</td></tr>\n"); sb.append( encodeData(entityData.getData(), Formats.HTML, null, null) ); sb.append(" </td></tr>\n"); } else { Map<String, Object> props = entityData.getEntityProperties(); if (!props.isEmpty()) { sb.append(" <table border='1'>\n"); if (EntityView.VIEW_LIST.equals(viewKey) && entityData != null && entityData.getEntityId() != null) { view.setEntityReference( new EntityReference(prefix, entityData.getEntityId()) );
for (Entry<String, Integer> entry : matchMap.entrySet()) { if (entry.getValue() >= allCount) { results.add( new EntityData(entry.getKey(), (String)null) ); refToTags.put(tagApp.getEntityRef(), tagApp.getTag()); results.add( new EntityData(tagApp.getEntityRef(), (String)null) ); String reference = ed.getEntityReference().toString(); ed.getEntityProperties().put("tags", refToTags.get(reference));
Object lm = ed.getEntityProperties().get("lastModified"); if (lm != null) { Long l = makeLastModified(lm); if (ed.getData() != null) { lm = ReflectUtils.getInstance().getFieldValue(ed.getData(), "lastModified", EntityLastModified.class); Long l = makeLastModified(lm); if (l != null) {
ref = new EntityReference(ed.getEntityRef().getPrefix(), ""); view.setEntityReference( ref ); view.setViewKey(EntityView.VIEW_LIST); EntityData ed = actionReturn.entityData; if (! ed.isDisplayTitleSet()) { ed.setDisplayTitle(customAction.action); entities = eList; ref = ed.getEntityRef(); if (ref == null) { ref = new EntityReference(prefix, customAction.action);
/** * Get the entity data for a reference if possible * * @param ref an entity reference * @return an {@link EntityData} object for this reference if one can be found OR null if not */ public EntityData getEntityData(EntityReference ref) { if (ref == null) { throw new IllegalArgumentException("ref cannot be null"); } EntityData ed = null; Object obj = fetchEntityObject(ref); if (obj != null) { ed = EntityDataUtils.makeEntityData(ref, obj); populateEntityData(new EntityData[] {ed} ); } else { if (entityExists(ref)) { String url = getEntityURL(ref.toString(), EntityView.VIEW_SHOW, null); ed = new EntityData(ref, (String)null); ed.setEntityURL(url); } } return ed; }
@Override public String toString() { return "ED: ref="+entityReference+":display="+entityDisplayTitle+":url="+entityURL+":props("+getEntityProperties().size()+"):dataOnly="+dataOnly+":data="+data; }
/** * Convert an entity/data to just an entity, * will preserve null (i.e. null in => null out) */ public static Object convertToEntity(Object object) { Object togo = null; if (object != null) { if (EntityData.class.isAssignableFrom(object.getClass())) { EntityData ed = (EntityData)object; if (ed.getData() != null) { togo = ed.getData(); } else { togo = ed; } } else { togo = object; } } return togo; }
/** * @deprecated use {@link #findEntitesByTags(String[], String[], boolean, Search)} */ public List<String> findEntityRefsByTags(String[] tags) { if (tagSearchService != null) { ArrayList<String> refs = new ArrayList<String>(); List<EntityData> results = tagSearchService.findEntitesByTags(tags, null, false, null); for (EntityData entitySearchResult : results) { refs.add( entitySearchResult.getEntityReference() ); } return refs; } else { log.warn("No tagSearchService defined"); return new ArrayList<String>(); } }
sb.append("NO DATA to encode"); } else { sb.append(" <div style='font-weight:bold;'>"+StringEscapeUtils.escapeHtml(entityData.getDisplayTitle())+"</div>\n"); sb.append(" <table border='1'>\n"); sb.append(" <caption style='font-weight:bold;'>Entity Data</caption>\n"); if (! entityData.isDataOnly()) { sb.append(" <tr><td>entityReference</td><td>"+StringEscapeUtils.escapeHtml(entityData.getEntityReference())+"</td></tr>\n"); sb.append(" <tr><td>entityURL</td><td>"+StringEscapeUtils.escapeHtml(entityData.getEntityURL())+"</td></tr>\n"); if (entityData.getEntityRef() != null) { sb.append(" <tr><td>entityPrefix</td><td>"+StringEscapeUtils.escapeHtml(entityData.getEntityRef().getPrefix())+"</td></tr>\n"); if (entityData.getEntityRef().getId() != null) { sb.append(" <tr><td>entityID</td><td>"+StringEscapeUtils.escapeHtml(entityData.getEntityRef().getId())+"</td></tr>\n"); if (entityData.getData() != null) { sb.append(" <tr><td>entity-type</td><td>"+entityData.getData().getClass().getName()+"</td></tr>\n"); sb.append( encodeData(entityData.getData(), Formats.HTML, null, null) ); sb.append(" </td></tr>\n"); } else { Map<String, Object> props = entityData.getEntityProperties(); if (!props.isEmpty()) { sb.append(" <table border='1'>\n"); if (EntityView.VIEW_LIST.equals(viewKey) && entityData != null && entityData.getEntityId() != null) { view.setEntityReference( new EntityReference(prefix, entityData.getEntityId()) );
Object lm = ed.getEntityProperties().get("lastModified"); if (lm != null) { Long l = makeLastModified(lm); if (ed.getData() != null) { lm = ReflectUtils.getInstance().getFieldValue(ed.getData(), "lastModified", EntityLastModified.class); Long l = makeLastModified(lm); if (l != null) {
ref = new EntityReference(ed.getEntityRef().getPrefix(), ""); view.setEntityReference( ref ); view.setViewKey(EntityView.VIEW_LIST); EntityData ed = actionReturn.entityData; if (! ed.isDisplayTitleSet()) { ed.setDisplayTitle(customAction.action); entities = eList; ref = ed.getEntityRef(); if (ref == null) { ref = new EntityReference(prefix, customAction.action);
/** * Full constructor<br/> * Use this if you want to return the entity itself along with the key meta data and properties * * @param reference a globally unique reference to an entity, * consists of the entity prefix and id (e.g. /prefix/id) * @param entityDisplayTitle 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 entity represented by an entity * @param data an entity data object, see {@link Resolvable} * @param entityProperties a set of properties to return along with the entity information, * this may be presented and used for filtering, */ public EntityData(String reference, String displayTitle, Object entity, Map<String, Object> entityProperties) { this.entityRef = new EntityReference(reference); this.entityReference = this.entityRef.getReference(); this.entityId = this.entityRef.getId(); this.entityDisplayTitle = displayTitle; this.entityURL = EntityView.DIRECT_PREFIX + this.entityReference; setData(entity); setEntityProperties(entityProperties); }
public List<EntityData> findEntitesByTags(String[] tags, boolean matchAll, Search search) { Set<String> refs = new HashSet<String>(); if (matchAll) { HashSet<String> allTags = new HashSet<String>(); for (int i = 0; i < tags.length; i++) { allTags.add(tags[i]); } for (Entry<String, Set<String>> entry : entityTags.entrySet()) { if (entry.getValue().containsAll(allTags)) { refs.add(entry.getKey()); } } } else { for (String key : entityTags.keySet()) { Set<String> s = entityTags.get(key); for (int i = 0; i < tags.length; i++) { if (s.contains(tags[i])) { refs.add(key); } } } } ArrayList<EntityData> results = new ArrayList<EntityData>(); for (String ref : refs) { results.add( new EntityData(ref, (String)null) ); } Collections.sort(results, new EntityData.ReferenceComparator()); return results; }