/** Constructor. */ protected AbstractItem() { metadata = new ClassToInstanceMultiMap<>(true); }
/** {@inheritDoc} */ @Override protected void doExecute(final Collection<Item<T>> itemCollection) throws StageProcessingException { // we make a defensive copy here in case logic in the delegate #doExecute makes changes // to the itemCollection and thus would cause issues if we were iterating over it directly final ArrayList<Item<T>> collectionCopy = new ArrayList<>(itemCollection); for (Item<T> item : collectionCopy) { final HashMap<Class<? extends ItemMetadata>, List<? extends ItemMetadata>> matchingMetadata = new HashMap<>(); for (Class<? extends ItemMetadata> infoClass : selectionRequirements) { if (item.getItemMetadata().containsKey(infoClass)) { matchingMetadata.put(infoClass, item.getItemMetadata().get(infoClass)); } } if (!matchingMetadata.isEmpty()) { doExecute(itemCollection, item, matchingMetadata); } } }
/** * Add an {@link ErrorStatus} to the given {@link Item}. * * @param message message to include in the status metadata * @param item {@link Item} to add the status metadata to * @param stageId component identifier for the calling stage */ protected void addError(@Nonnull final String message, @Nonnull final Item<?> item, @Nonnull final String stageId) { item.getItemMetadata().put(new ErrorStatus(makeComponentId(stageId), message)); }
/** {@inheritDoc} */ @Override protected boolean doExecute(@Nonnull final Item<T> item) throws StageProcessingException { final List<ItemId> ids = item.getItemMetadata().get(ItemId.class); final List<ItemId> transformedIds = new ArrayList<>(); for (ItemId id : ids) { for (Converter<String, String> idTransform : idTransformers) { final String transformedId = idTransform.convert(id.getId()); transformedIds.add(new ItemId(transformedId)); } } item.getItemMetadata().putAll(transformedIds); return true; } }
@Override protected void visit(@Nonnull final Element element, @Nonnull final TraversalContext context) throws StageProcessingException { final String text = element.getTextContent(); final byte[] data = Base64Support.decode(text); try { final X509Certificate cert = (X509Certificate) factory.generateCertificate(new ByteArrayInputStream(data)); // only process each certificate once per item if (!context.getStash().containsValue(cert)) { context.getStash().put(cert); applyValidators(cert, context); } } catch (CertificateException e) { context.getItem().getItemMetadata().put(new ErrorStatus(getId(), "could not convert X509Certificate data")); } }
@Override protected void visit(final Element element, final TraversalContext context) throws StageProcessingException { if (!context.getStash().isEmpty()) { return; context.getStash().put(Boolean.TRUE); return; if (attribute.getNodeValue().indexOf(CR) >= 0) { addError(item, element, "attribute value contains a carriage return character"); context.getStash().put(Boolean.TRUE); return;
@Override @Nullable protected String getBasicIdentifier(@Nonnull final Item<?> item) { final List<ItemId> itemIds = item.getItemMetadata().get(ItemId.class); if (!itemIds.isEmpty()) { return itemIds.get(0).getId(); } else { return null; } }
/** {@inheritDoc} */ @Override protected void executeTransformer(@Nonnull final Transformer transformer, @Nonnull @NonnullElements final Collection<Item<Element>> itemCollection) throws StageProcessingException, TransformerConfigurationException { try { final ArrayList<Item<Element>> newItems = new ArrayList<>(); for (Item<Element> domItem : itemCollection) { transformer.setErrorListener(new StatusInfoAppendingErrorListener(domItem)); final Element element = domItem.unwrap(); // Create a new document to hold the result of the transform. final DOMImplementation domImpl = element.getOwnerDocument().getImplementation(); final Document newDocument = domImpl.createDocument(null, null, null); // perform the transformation transformer.transform(new DOMSource(element.getOwnerDocument()), new DOMResult(newDocument)); // Create the result Item and copy across the input's ItemMetadata objects. final Item<Element> newItem = new DOMElementItem(newDocument); ItemMetadataSupport.addAll(newItem, domItem.getItemMetadata().values()); newItems.add(newItem); } itemCollection.clear(); itemCollection.addAll(newItems); } catch (TransformerException e) { throw new StageProcessingException("Unable to transform DOM Element", e); } } }
/** {@inheritDoc} */ @Override protected boolean doExecute(@Nonnull final Item<T> item) throws StageProcessingException { item.getItemMetadata().putAll(additionalItemMetadata); return true; } }
/** * Extract the registration authority for an entity from its entity metadata. * * @param item the {@link Item} representing the entity * @return the registration authority URI, or <code>null</code> if not present */ private String extractRegistrationAuthority(@Nonnull final Item<Element> item) { final List<RegistrationAuthority> regAuthList = item.getItemMetadata().get(RegistrationAuthority.class); if (regAuthList.isEmpty()) { return null; } else { return regAuthList.get(0).getRegistrationAuthority(); } }
for (Element transformedElement : transformedElements) { DOMElementItem newItem = new DOMElementItem(transformedElement); ItemMetadataSupport.addAll(newItem, domItem.getItemMetadata().values()); newItems.add(newItem);
/** * Add a {@link WarningStatus} to the given {@link Item}. * * @param message message to include in the status metadata * @param item {@link Item} to add the status metadata to * @param stageId component identifier for the calling stage */ protected void addWarning(@Nonnull final String message, @Nonnull final Item<?> item, @Nonnull final String stageId) { item.getItemMetadata().put(new WarningStatus(makeComponentId(stageId), message)); }
final List<RegistrationAuthority> regAuths = item.getItemMetadata().get(RegistrationAuthority.class);
/** Constructor. */ public ItemCollectionWithMetadata() { delegate = new LazyList<>(); metadata = new ClassToInstanceMultiMap<>(true); }
/** {@inheritDoc} */ @Override public Item<Element> copy() { final DOMElementItem clone = new DOMElementItem(unwrap()); ItemMetadataSupport.addAll(clone, getItemMetadata().values()); return clone; } }
/** * Adds all the given {@link ItemMetadata} items to the given {@link Item} element. * * @param item element to which {@link ItemMetadata} will be added * @param metadatas {@link ItemMetadata} to be added to the metadata element */ public static void addAll(@Nullable final Item<?> item, @Nullable @NullableElements final Iterable<? extends ItemMetadata> metadatas) { if (item == null || metadatas == null) { return; } for (ItemMetadata metadata : metadatas) { if (metadata != null) { item.getItemMetadata().put(metadata); } } }
@Override public Destination getDestination(final Item<T> item) throws StageProcessingException { // Locate the item's identifier. final List<ItemId> ids = item.getItemMetadata().get(ItemId.class); if (ids.isEmpty()) { throw new StageProcessingException("item has no ItemId to base a file name on"); } final ItemId id = ids.get(0); // Construct file name final String name = namePrefix + nameTransformer.apply(id.getId()) + nameSuffix; log.debug("id mapped {} -> {}", id.getId(), name); // Locate the output file within the directory final File outputFile = new File(directory, name); return new FileDestination(outputFile); }
/** * Constructor. * * @param wrappedCollection the underlying collection that holds the items */ public ItemCollectionWithMetadata(@Nonnull @NonnullElements final Collection<Item<T>> wrappedCollection) { delegate = Constraint.isNotNull(wrappedCollection, "Wrapped collection can not be null"); delegate.clear(); metadata = new ClassToInstanceMultiMap<>(true); }
/** * Adds one or more {@link ItemMetadata} to the given collection if the collection is an instance of * {@link ItemCollectionWithMetadata}. * * @param itemCollection collection to which the metadata may be added * @param itemMetadatas the metadata which may be added to the collection * @param <T> type of item in the collections */ public static <T> void addToCollection(@Nullable final Collection<Item<T>> itemCollection, @Nullable @NullableElements final Iterable<? extends ItemMetadata> itemMetadatas) { if (itemCollection == null || !(itemCollection instanceof ItemCollectionWithMetadata)) { return; } if (itemMetadatas == null) { return; } ItemCollectionWithMetadata<T> collection = (ItemCollectionWithMetadata<T>) itemCollection; for (ItemMetadata metadata : itemMetadatas) { if (metadata != null) { collection.getCollectionMetadata().put(metadata); } } } }
List<ItemId> itemIds; for (Item<T> sourceItem : sourceItems) { itemIds = sourceItem.getItemMetadata().get(ItemId.class); if (itemIds == null || itemIds.isEmpty()) { target.add(sourceItem);