@Override public void customWriteBody(T value, JsonGenerator jgen, SerializerProvider provider) throws IOException { Optional<String> entityId = getEntityId(value); jgen.writeStringField("id", value.getId()); if (entityId.isPresent()) jgen.writeStringField("entityId", entityId.get()); } @Override
String oldItemTag = oldItem.getUniqueTag(); String newItemTag = newItem.getUniqueTag(); if (oldItemTag!=null || newItemTag!=null) { if (Objects.equal(oldItemTag, newItemTag)) { LOG.warn("Apparently equal items "+oldItem+" and "+newItem+"; but one has a unique tag "+tagged.getUniqueTag()+"; applying to the other"); ((AdjunctTagSupport)tagless.tags()).setUniqueTag(tagged.getUniqueTag());
public static <T extends EntityAdjunct> Maybe<T> tryFindWithUniqueTag(Iterable<T> adjuncts, Object tag) { Preconditions.checkNotNull(tag, "tag"); for (T adjunct: adjuncts) if (tag.equals(adjunct.getUniqueTag())) return Maybe.of(adjunct); return Maybe.absent("Not found with tag "+tag); }
beforeEntityAdjunct = beforeEntityAdjunct.getSuperclass(); String newItemTag = newItem.getUniqueTag(); for (T oldItem: itemsCopy) { String oldItemTag = oldItem.getUniqueTag(); if (oldItemTag!=null && newItemTag!=null) { if (oldItemTag.equals(newItemTag)) {
private static void populateBrooklynObjectMementoBuilder(BrooklynObject instance, AbstractMemento.Builder<?> builder) { if (Proxy.isProxyClass(instance.getClass())) { throw new IllegalStateException("Attempt to create memento from proxy "+instance+" (would fail with wrong type)"); } OsgiClassPrefixer prefixer = new OsgiClassPrefixer(); Optional<String> typePrefix = prefixer.getPrefix(instance.getClass()); builder.id = instance.getId(); builder.displayName = instance.getDisplayName(); builder.catalogItemId = instance.getCatalogItemId(); builder.searchPath = instance.getCatalogItemIdSearchPath(); builder.type = (typePrefix.isPresent() ? typePrefix.get() : "") + instance.getClass().getName(); builder.typeClass = instance.getClass(); if (instance instanceof EntityAdjunct) { builder.uniqueTag = ((EntityAdjunct)instance).getUniqueTag(); } for (Object tag : instance.tags().getTags()) { builder.tags.add(tag); } // CatalogItems return empty support, so this is safe even through they don't support relations for (RelationshipType<?,? extends BrooklynObject> relationship: instance.relations().getRelationshipTypes()) { @SuppressWarnings({ "unchecked", "rawtypes" }) Set relations = instance.relations().getRelations((RelationshipType)relationship); Set<String> relationIds = Sets.newLinkedHashSet(); for (Object r: relations) relationIds.add( ((BrooklynObject)r).getId() ); builder.relations.put(relationship.getRelationshipTypeName(), relationIds); } }