List of usage examples for org.joda.time.format ISODateTimeFormat dateTime
public static DateTimeFormatter dateTime()
From source file:org.n52.sos.feeder.baw.task.FeedObservationThread.java
License:Open Source License
/** * Gets the last update time.//from w w w . ja va 2 s .c o m * * @param samplingTime * the sampling time * @return the last update time */ private Calendar getLastUpdateTime(TimeObjectPropertyType samplingTime) { AbstractTimeObjectType timeObject = samplingTime.getTimeObject(); TimePeriodType timePeriod = (TimePeriodType) timeObject; DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); Date date = null; try { DateTime dateTime = fmt.parseDateTime(timePeriod.getEndPosition().getStringValue()); date = dateTime.toDate(); } catch (Exception e) { log.error("Error when parsing Date: " + e.getMessage(), e); } Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal; }
From source file:org.nuxeo.box.api.adapter.BoxAdapter.java
License:Open Source License
public BoxAdapter(DocumentModel doc) throws ClientException { this.doc = doc; CoreSession session = doc.getCoreSession(); boxProperties.put(BoxItem.FIELD_ID, boxService.getBoxId(doc)); boxProperties.put(BoxItem.FIELD_SEQUENCE_ID, boxService.getBoxSequenceId(doc)); boxProperties.put(BoxItem.FIELD_ETAG, boxService.getBoxEtag(doc)); boxProperties.put(BoxItem.FIELD_NAME, doc.getName()); boxProperties.put(BoxItem.FIELD_CREATED_AT, ISODateTimeFormat.dateTime().print(new DateTime(doc.getPropertyValue("dc:created")))); boxProperties.put(BoxItem.FIELD_MODIFIED_AT, ISODateTimeFormat.dateTime().print(new DateTime(doc.getPropertyValue("dc:modified")))); boxProperties.put(BoxItem.FIELD_DESCRIPTION, doc.getPropertyValue("dc:description")); // size/*from w ww .ja va2 s . c o m*/ QuotaAwareDocument quotaAwareDocument = null; if (Framework.getRuntime().getBundle("org.nuxeo.ecm.quota.core") != null) { quotaAwareDocument = (QuotaAwareDocument) doc.getAdapter(QuotaAware.class); } boxProperties.put(BoxItem.FIELD_SIZE, quotaAwareDocument != null ? quotaAwareDocument.getInnerSize() : -1.0); // path_collection final DocumentModel parentDoc = session.getParentDocument(doc.getRef()); final Map<String, Object> pathCollection = new HashMap<>(); List<BoxTypedObject> hierarchy = getParentsHierarchy(session, parentDoc); pathCollection.put(BoxCollection.FIELD_ENTRIES, hierarchy); pathCollection.put(BoxCollection.FIELD_TOTAL_COUNT, hierarchy.size()); BoxCollection boxPathCollection = new BoxCollection(Collections.unmodifiableMap(pathCollection)); boxProperties.put(BoxItem.FIELD_PATH_COLLECTION, boxPathCollection); // parent final Map<String, Object> parentProperties = new HashMap<>(); parentProperties.put(BoxItem.FIELD_ID, boxService.getBoxId(parentDoc)); parentProperties.put(BoxItem.FIELD_SEQUENCE_ID, boxService.getBoxSequenceId(parentDoc)); parentProperties.put(BoxItem.FIELD_NAME, boxService.getBoxName(parentDoc)); parentProperties.put(BoxItem.FIELD_ETAG, boxService.getBoxEtag(parentDoc)); BoxFolder parentFolder = new BoxFolder(Collections.unmodifiableMap(parentProperties)); boxProperties.put(BoxItem.FIELD_PARENT, parentFolder); // Users // Creator final UserManager userManager = Framework.getLocalService(UserManager.class); String creator = doc.getPropertyValue("dc:creator") != null ? (String) doc.getPropertyValue("dc:creator") : "system"; NuxeoPrincipal principalCreator = userManager.getPrincipal(creator); final BoxUser boxCreator = boxService.fillUser(principalCreator); boxProperties.put(BoxItem.FIELD_CREATED_BY, boxCreator); // Last Contributor String lastContributor = doc.getPropertyValue("dc:lastContributor") != null ? (String) doc.getPropertyValue("dc:lastContributor") : "system"; final NuxeoPrincipal principalLastContributor = userManager.getPrincipal(lastContributor); final BoxUser boxContributor = boxService.fillUser(principalLastContributor); boxProperties.put(BoxItem.FIELD_MODIFIED_BY, boxContributor); // Owner boxProperties.put(BoxItem.FIELD_OWNED_BY, boxCreator); // Shared Link boxProperties.put(BoxItem.FIELD_SHARED_LINK, null); // Status boxProperties.put(BoxItem.FIELD_ITEM_STATUS, doc.getCurrentLifeCycleState()); // Tags boxProperties.put(BoxItem.FIELD_TAGS, getTags(session)); }
From source file:org.nuxeo.box.api.comment.adapter.BoxCommentAdapter.java
License:Open Source License
/** * Instantiate the adapter and the Box Comment from Nuxeo Document and load its properties into json format *//* w ww. j av a 2 s. c om*/ public BoxCommentAdapter(DocumentModel doc) throws ClientException { BoxService boxService = Framework.getLocalService(BoxService.class); comment = doc; boxProperties.put(BoxComment.FIELD_ID, doc.getId()); boxProperties.put(BoxComment.FIELD_CREATED_AT, ISODateTimeFormat.dateTime().print(new DateTime(doc.getPropertyValue("comment:creationDate")))); // Nuxeo comment doesn't provide modified date boxProperties.put(BoxComment.FIELD_MODIFIED_AT, ISODateTimeFormat.dateTime().print(new DateTime(doc.getPropertyValue("dc:modified")))); // Comment Author final UserManager userManager = Framework.getLocalService(UserManager.class); final NuxeoPrincipal creator = userManager.getPrincipal((String) doc.getPropertyValue("comment:author")); final BoxUser boxCreator = boxService.fillUser(creator); boxProperties.put(BoxComment.FIELD_CREATED_BY, boxCreator); boxProperties.put(BoxComment.FIELD_MESSAGE, doc.getPropertyValue("comment:text")); boxProperties.put(BoxComment.FIELD_IS_REPLY_COMMENT, null); boxProperties.put(BoxComment.FIELD_ITEM, fillItem(doc)); boxComment = new BoxComment(boxProperties); }
From source file:org.nuxeo.box.api.file.adapter.BoxFileAdapter.java
License:Open Source License
/** * Instantiate the adapter and the Box File from Nuxeo Document and load its properties into json format *///from ww w . ja va 2s . c om public BoxFileAdapter(DocumentModel doc) throws ClientException { super(doc); // MD5 Blob blob = (Blob) doc.getPropertyValue("file:content"); if (blob != null) { boxProperties.put(BoxFile.FIELD_SHA1, blob.getDigest()); } // Lock Map<String, Object> boxLockProperties = new HashMap<>(); Lock lockInfo = doc.getLockInfo(); if (lockInfo != null) { boxLockProperties.put(BoxItem.FIELD_ID, null); final UserManager userManager = Framework.getLocalService(UserManager.class); final NuxeoPrincipal lockCreator = userManager.getPrincipal(lockInfo.getOwner()); final BoxUser boxLockCreator = boxService.fillUser(lockCreator); boxLockProperties.put(BoxItem.FIELD_CREATED_BY, boxLockCreator); boxLockProperties.put(BoxItem.FIELD_CREATED_AT, ISODateTimeFormat.dateTime().print(new DateTime(lockInfo.getCreated()))); boxLockProperties.put(BoxLock.FIELD_EXPIRES_AT, null); boxLockProperties.put(BoxLock.FIELD_IS_DOWNLOAD_PREVENTED, false); BoxLock boxLock = new BoxLock(boxLockProperties); boxProperties.put(BoxConstants.BOX_LOCK, boxLock); } boxItem = new BoxFile(Collections.unmodifiableMap(boxProperties)); }
From source file:org.nuxeo.ecm.automation.jaxrs.io.audit.LogEntryWriter.java
License:Open Source License
@Override protected void writeEntityBody(JsonGenerator jg, LogEntry logEntry) throws IOException, ClientException { jg.writeStringField("entity-type", "logEntry"); jg.writeStringField("category", logEntry.getCategory()); jg.writeStringField("principalName", logEntry.getPrincipalName()); jg.writeStringField("comment", logEntry.getComment()); jg.writeStringField("docLifeCycle", logEntry.getDocLifeCycle()); jg.writeStringField("docPath", logEntry.getDocPath()); jg.writeStringField("docType", logEntry.getDocType()); jg.writeStringField("docUUID", logEntry.getDocUUID()); jg.writeStringField("eventId", logEntry.getEventId()); jg.writeStringField("repositoryId", logEntry.getRepositoryId()); jg.writeStringField("eventDate", ISODateTimeFormat.dateTime().print(new DateTime(logEntry.getEventDate()))); jg.writeNumberField("id", logEntry.getId()); jg.writeStringField("logDate", ISODateTimeFormat.dateTime().print(new DateTime(logEntry.getLogDate()))); }
From source file:org.nuxeo.ecm.automation.jaxrs.io.documents.JsonDocumentWriter.java
License:Open Source License
/** * * @param jg a ready to user JSON generator * @param doc the document to serialize// www . jav a 2 s .c o m * @param schemas an array of schemas that must be serialized in the * properties map * @param contextParameters * @param headers * @param request the ServletRequest. If null blob URLs won't be generated. * @throws Exception * * @since 5.7.3 */ public static void writeDocument(JsonGenerator jg, DocumentModel doc, String[] schemas, Map<String, String> contextParameters, HttpHeaders headers, ServletRequest request) throws Exception { jg.writeStartObject(); jg.writeStringField("entity-type", "document"); jg.writeStringField("repository", doc.getRepositoryName()); jg.writeStringField("uid", doc.getId()); jg.writeStringField("path", doc.getPathAsString()); jg.writeStringField("type", doc.getType()); jg.writeStringField("state", doc.getRef() != null ? doc.getCurrentLifeCycleState() : null); jg.writeStringField("parentRef", doc.getParentRef() != null ? doc.getParentRef().toString() : null); jg.writeStringField("versionLabel", doc.getVersionLabel()); jg.writeBooleanField("isCheckedOut", doc.isCheckedOut()); Lock lock = doc.getLockInfo(); if (lock != null) { jg.writeStringField("lockOwner", lock.getOwner()); jg.writeStringField("lockCreated", ISODateTimeFormat.dateTime().print(new DateTime(lock.getCreated()))); } jg.writeStringField("title", doc.getTitle()); try { Calendar cal = (Calendar) doc.getPropertyValue("dc:modified"); if (cal != null) { jg.writeStringField("lastModified", DateParser.formatW3CDateTime(cal.getTime())); } } catch (PropertyNotFoundException e) { // ignore } if (schemas != null && schemas.length > 0) { jg.writeObjectFieldStart("properties"); if (schemas.length == 1 && "*".equals(schemas[0])) { // full document for (String schema : doc.getSchemas()) { writeProperties(jg, doc, schema, request); } } else { for (String schema : schemas) { writeProperties(jg, doc, schema, request); } } jg.writeEndObject(); } jg.writeArrayFieldStart("facets"); for (String facet : doc.getFacets()) { jg.writeString(facet); } jg.writeEndArray(); jg.writeStringField("changeToken", doc.getChangeToken()); jg.writeObjectFieldStart("contextParameters"); if (contextParameters != null && !contextParameters.isEmpty()) { for (Map.Entry<String, String> parameter : contextParameters.entrySet()) { jg.writeStringField(parameter.getKey(), parameter.getValue()); } } writeRestContributions(jg, doc, headers, request); jg.writeEndObject(); jg.writeEndObject(); jg.flush(); }
From source file:org.nuxeo.ecm.core.io.marshallers.json.document.DocumentModelJsonWriter.java
License:Apache License
@Override protected void writeEntityBody(DocumentModel doc, JsonGenerator jg) throws IOException { jg.writeStringField("repository", doc.getRepositoryName()); jg.writeStringField("uid", doc.getId()); jg.writeStringField("path", doc.getPathAsString()); jg.writeStringField("type", doc.getType()); jg.writeStringField("state", doc.getRef() != null ? doc.getCurrentLifeCycleState() : null); jg.writeStringField("parentRef", doc.getParentRef() != null ? doc.getParentRef().toString() : null); jg.writeBooleanField("isCheckedOut", doc.isCheckedOut()); jg.writeBooleanField("isVersion", doc.isVersion()); jg.writeBooleanField("isProxy", doc.isProxy()); jg.writeStringField("changeToken", doc.getChangeToken()); jg.writeStringField("title", doc.getTitle()); if (mustFetch("versionLabel")) { String versionLabel = doc.getVersionLabel(); jg.writeStringField("versionLabel", versionLabel != null ? versionLabel : ""); }//from w ww. ja va2s .c om if (mustFetch("lock")) { Lock lock = doc.getLockInfo(); if (lock != null) { jg.writeStringField("lockOwner", lock.getOwner()); jg.writeStringField("lockCreated", ISODateTimeFormat.dateTime().print(new DateTime(lock.getCreated()))); } } if (doc.hasSchema("dublincore")) { Calendar cal = (Calendar) doc.getPropertyValue("dc:modified"); if (cal != null) { jg.writeStringField("lastModified", DateParser.formatW3CDateTime(cal.getTime())); } } try (Closeable resource = ctx.wrap().controlDepth().open()) { Set<String> schemas = ctx.getProperties(); if (schemas.size() > 0) { jg.writeObjectFieldStart("properties"); if (schemas.contains(WILDCARD_VALUE)) { // full document for (String schema : doc.getSchemas()) { writeSchemaProperties(jg, doc, schema); } } else { for (String schema : schemas) { if (doc.hasSchema(schema)) { writeSchemaProperties(jg, doc, schema); } } } jg.writeEndObject(); } } catch (MaxDepthReachedException e) { // do not load properties } jg.writeArrayFieldStart("facets"); for (String facet : doc.getFacets()) { jg.writeString(facet); } jg.writeEndArray(); }
From source file:org.nuxeo.ecm.core.rest.LockService.java
License:Open Source License
@GET public Object doGet() { try {//from w w w .ja va2s . c o m DocumentModel doc = getTarget().getAdapter(DocumentModel.class); Lock lock = ctx.getCoreSession().getLockInfo(doc.getRef()); return lock.getOwner() + '/' + ISODateTimeFormat.dateTime().print(new DateTime(lock.getCreated())); } catch (Exception e) { throw WebException.wrap("Failed to get lock on document", e); } }
From source file:org.nuxeo.ecm.permissions.ACLJsonEnricher.java
License:Apache License
protected void writeACEsField(JsonGenerator jg, String fieldName, ACL acl, DocumentModel document) throws IOException { jg.writeArrayFieldStart(fieldName);//from ww w. j a v a 2 s . c o m for (ACE ace : acl.getACEs()) { jg.writeStartObject(); jg.writeStringField("id", ace.getId()); String username = ace.getUsername(); writePrincipalOrGroup(USERNAME_PROPERTY, username, jg); jg.writeBooleanField("externalUser", NuxeoPrincipal.isTransientUsername(username)); jg.writeStringField("permission", ace.getPermission()); jg.writeBooleanField("granted", ace.isGranted()); writePrincipalOrGroup(CREATOR_PROPERTY, ace.getCreator(), jg); DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime(); jg.writeStringField("begin", ace.getBegin() != null ? dateTimeFormatter.print(new DateTime(ace.getBegin())) : null); jg.writeStringField("end", ace.getEnd() != null ? dateTimeFormatter.print(new DateTime(ace.getEnd())) : null); jg.writeStringField("status", ace.getStatus().toString().toLowerCase()); if (ctx.getFetched(NAME).contains(EXTENDED_ACLS_PROPERTY)) { Map<String, Serializable> m = computeAdditionalFields(document, acl.getName(), ace.getId()); for (Map.Entry<String, Serializable> entry : m.entrySet()) { jg.writeObjectField(entry.getKey(), entry.getValue()); } } jg.writeEndObject(); } jg.writeEndArray(); }
From source file:org.nuxeo.ecm.platform.audit.io.LogEntryJsonWriter.java
License:Apache License
@Override protected void writeEntityBody(LogEntry logEntry, JsonGenerator jg) throws IOException { jg.writeNumberField("id", logEntry.getId()); jg.writeStringField("category", logEntry.getCategory()); jg.writeStringField("principalName", logEntry.getPrincipalName()); jg.writeStringField("comment", logEntry.getComment()); jg.writeStringField("docLifeCycle", logEntry.getDocLifeCycle()); jg.writeStringField("docPath", logEntry.getDocPath()); jg.writeStringField("docType", logEntry.getDocType()); jg.writeStringField("docUUID", logEntry.getDocUUID()); jg.writeStringField("eventId", logEntry.getEventId()); jg.writeStringField("repositoryId", logEntry.getRepositoryId()); DateTimeFormatter dateTime = ISODateTimeFormat.dateTime(); jg.writeStringField("eventDate", dateTime.print(new DateTime(logEntry.getEventDate()))); jg.writeStringField("logDate", dateTime.print(new DateTime(logEntry.getLogDate()))); writeExtendedInfos(jg, logEntry);//from w w w . j a va 2 s.com }