@Override public Item populateItem(T newValue, Item item) { super.populateItem(newValue, item); newValue.updateRelatedProperties(); // since DAM 2.0 we store filename + extension in the fileName property getOrCreateProperty(item, AssetNodeTypes.AssetResource.FILENAME, String.class).setValue(newValue.getFileName()); if (newValue.isImage() && newValue.getFileSize() > 0) { // Set getOrCreateProperty(item, AssetNodeTypes.AssetResource.WIDTH, Long.class).setValue(newValue.getWidth()); getOrCreateProperty(item, AssetNodeTypes.AssetResource.HEIGHT, Long.class).setValue(newValue.getHeight()); // Remove item.removeItemProperty("duration"); } else if (newValue.getDuration() > 0) { // Set getOrCreateProperty(item, "duration", Long.class).setValue(newValue.getDuration()); // Remove item.removeItemProperty(AssetNodeTypes.AssetResource.WIDTH); item.removeItemProperty(AssetNodeTypes.AssetResource.HEIGHT); } else { // Remove item.removeItemProperty("duration"); item.removeItemProperty(AssetNodeTypes.AssetResource.WIDTH); item.removeItemProperty(AssetNodeTypes.AssetResource.HEIGHT); } return item; } }
@Test public void executeRemovesProperty() throws RepositoryException, ActionExecutionException { // GIVEN Node node = session.getRootNode().addNode("underlying"); node.setProperty("property", "initial"); Item item = new JcrNodeAdapter(node); item.removeItemProperty("property"); assertEquals(true, node.hasProperty("property")); SaveDialogAction<SaveDialogActionDefinition> action = new SaveDialogAction<>(definition, item, validator, callback); // WHEN action.execute(); // THEN node = session.getRootNode().getNode("underlying"); assertEquals(false, node.hasProperty("property")); }