@Override public Calendar getModificationDate() { return (Calendar) doc.getProperty("dublincore", "modified"); }
@Override public void setBlob(Blob blob) { doc.getProperty(xPath).setValue(blob); }
/** * The given propertyName should have 'schema_name:property_name' format. * * @return <code>null</code> if any error occurs. */ public static Object getPropertyValue(DocumentModel doc, String propertyName) { try { String schemaName = getSchemaName(propertyName); String fieldName = getFieldName(propertyName); return doc.getProperty(schemaName, fieldName); } catch (PropertyException e) { log.warn("Error trying to get property " + propertyName + ". " + e.getMessage()); if (log.isDebugEnabled()) { log.debug(e); } return null; } }
/** * Gets the blob properties of the document. * * @param doc the document * @return the list of blob properties */ public List<Property> getBlobsProperties(DocumentModel doc) { List<Property> properties = new ArrayList<>(); for (String path : getBlobPaths(doc.getDocumentType())) { if (!isInterestingPath(path)) { continue; } List<String> split = Arrays.asList(path.split("/[*]/")); if (split.isEmpty()) { throw new IllegalStateException("Path detected not well-formed: " + path); } Property property = doc.getProperty(split.get(0)); List<String> subPath = split.subList(1, split.size()); findBlobsProperties(property, subPath, properties); } return properties; }
@Override public void setBlob(Blob blob) { if (blob == null) { doc.getProperty(xPath).setValue(null); mt = null; } else { String string; try { string = blob.getString(); } catch (IOException e) { throw new NuxeoException(e); } // strip '\0 chars from text if (string.indexOf('\0') >= 0) { string = string.replace("\0", ""); } doc.getProperty(xPath).setValue(string); mt = blob.getMimeType(); } }
@Override public Blob getBlob() { String string = (String) doc.getProperty(xPath).getValue(); if (string == null) { return null; } Blob blob = Blobs.createBlob(string, mt); String ext = ".txt"; if ("text/html".equals(mt)) { ext = ".html"; } else if ("text/xml".equals(mt)) { ext = ".xml"; } else if ("text/x-web-markdown".equals(mt)) { ext = ".md"; } String title = doc.getTitle(); if (!title.endsWith(ext)) { title = title.concat(ext); } blob.setFilename(title); return blob; }
Property property = doc.getProperty(xPath); properties.add(0, property);
@Override public void mapProperties(CoreSession session, DocumentModel sourceDoc, DocumentModel targetDoc, String mapping) { Map<String, String> properties = getMapping(mapping); for (String keyProp : properties.keySet()) { // verify that mapping can be done Property sourceProperty = sourceDoc.getProperty(keyProp); Property targetProperty = targetDoc.getProperty(properties.get(keyProp)); Type sourceType = sourceProperty.getType(); Type targetType = targetProperty.getType(); if (!compatibleTypes(targetType, sourceType)) { throw new NuxeoException( String.format("Invalid mapping. Cannot map %s on type %s ", sourceType, targetType)); } targetDoc.setPropertyValue(targetProperty.getXPath(), sourceProperty.getValue()); } session.saveDocument(targetDoc); }
@Override public DocumentValidationReport validate(DocumentModel document, boolean dirtyOnly) { List<ConstraintViolation> violations = new ArrayList<>(); DocumentType docType = document.getDocumentType(); if (dirtyOnly) { for (DataModel dataModel : document.getDataModels().values()) { Schema schemaDef = getSchemaManager().getSchema(dataModel.getSchema()); for (String fieldName : dataModel.getDirtyFields()) { Field field = schemaDef.getField(fieldName); Property property = document.getProperty(field.getName().getPrefixedName()); List<PathNode> path = singletonList(new PathNode(property.getField())); violations.addAll(validateAnyTypeProperty(property.getSchema(), path, property, true, true)); } } } else { for (Schema schema : docType.getSchemas()) { for (Field field : schema.getFields()) { Property property = document.getProperty(field.getName().getPrefixedName()); List<PathNode> path = singletonList(new PathNode(property.getField())); violations.addAll(validateAnyTypeProperty(property.getSchema(), path, property, false, true)); } } } return new DocumentValidationReport(violations); }
@SuppressWarnings("unchecked") @Override public List<String> getMemberGroups() { return (List<String>) model.getProperty(config.schemaName, config.subGroupsField); }
@SuppressWarnings("unchecked") @Override public List<String> getParentGroups() { return (List<String>) model.getProperty(config.schemaName, config.parentGroupsField); }
/** property map implementation */ @Override public boolean containsKey(Object key) { try { doc.getProperty(key.toString()); return true; } catch (PropertyException e) { return false; } }
private static Date getCommentTimeStamp(DocumentModel comment) { Calendar creationDate; try { creationDate = (Calendar) comment.getProperty("dublincore", "created"); } catch (PropertyException e) { creationDate = null; } if (creationDate == null) { creationDate = Calendar.getInstance(); } return creationDate.getTime(); }
@Override public String getLabel() { String label = (String) model.getProperty(config.schemaName, config.labelField); return label == null ? getName() : label; }
@Override public List<String> getProjection(Map<String, Serializable> filter, Set<String> fulltext, String columnName) { DocumentModelList docList = query(filter, fulltext); List<String> result = new ArrayList<>(); for (DocumentModel docModel : docList) { Object obj = docModel.getProperty(schemaName, columnName); String propValue = String.valueOf(obj); result.add(propValue); } return result; }
protected List<Button> computeTaskButtons() { ListProperty props = (ListProperty) document.getProperty(PROP_TASK_BUTTONS); List<Button> btns = new ArrayList<>(props.size()); for (Property p : props) { btns.add(new Button(this, p)); } Collections.sort(btns); return btns; }
protected boolean shouldProcess(DocumentModel doc, String eventName) { return doc.hasFacet(VIDEO_FACET) && !doc.isProxy() && (Boolean.TRUE.equals(doc.getContextData(CTX_FORCE_INFORMATIONS_GENERATION)) || DOCUMENT_CREATED.equals(eventName) || doc.getProperty("file:content").isDirty()); }
@DELETE public Response doDelete() { try { doc.getProperty(xpath).remove(); } catch (PropertyNotFoundException e) { throw new NuxeoException("Failed to delete attached file into property: " + xpath, e, SC_BAD_REQUEST); } CoreSession session = ctx.getCoreSession(); session.saveDocument(doc); session.save(); return Response.noContent().build(); }
@Override public Serializable put(String key, Serializable value) { Property p = principal.getModel().getProperty(key); Serializable v = p.getValue(); p.setValue(value); return v; }
protected final String str(String propName, DocumentModel document) { Object val = document.getProperty(getSchemaName(propName), getFieldName(propName)); if (val == null) { return null; } if (val instanceof String) { return (String) val; } throw new NuxeoException("Doc property '" + propName + "' is not of String type."); }