boolean queryable = connector.isQueryable();
// fire NODE_ADDED for nt:file
connectorChangeSet.nodeCreated(docId, connector.idFor(resolvedPath.getParent().toFile()), docId, primaryType,
Collections.<Name>emptySet(), Collections.<Name, Property>emptyMap(), queryable);
// fire PROPERTY_ADDED for nt:file/jcr:created
Property createdProperty = connector.propertyFactory().create(JcrLexicon.CREATED, connector.createdTimeFor(file));
connectorChangeSet.propertyAdded(docId, primaryType, Collections.<Name>emptySet(), docId, createdProperty, queryable);
String owner = connector.ownerFor(file);
if (owner != null) {
// fire PROPERTY_ADDED for nt:file/jcr:createdBy
Property createdByProperty = connector.propertyFactory().create(JcrLexicon.CREATED_BY, owner);
connectorChangeSet.propertyAdded(docId, primaryType, Collections.<Name>emptySet(), docId, createdByProperty,
queryable);
}
if (Files.isRegularFile(resolvedPath, LinkOption.NOFOLLOW_LINKS)) {
// for files we need to fire extra events for their content
String contentId = connector.contentChildId(docId, false);
// fire NODE_ADDED for the nt:file/jcr:content
connectorChangeSet.nodeCreated(contentId, docId, contentId, JcrNtLexicon.RESOURCE, Collections.<Name>emptySet(),
Collections.<Name, Property>emptyMap(), queryable);
try {
// fire PROPERTY_ADDED for nt:file/jcr:content/jcr:data
BinaryValue binaryValue = connector.binaryFor(file);
Property dataProperty = connector.propertyFactory().create(JcrLexicon.DATA, binaryValue);
connectorChangeSet.propertyAdded(contentId, JcrNtLexicon.RESOURCE, Collections.<Name>emptySet(), contentId,
dataProperty, queryable);
if (connector.addMimeTypeMixin) {
try {
// fire PROPERTY_ADDED for nt:file/jcr:content/jcr:mimetype
String mimeType = binaryValue.getMimeType();
Property mimeTypeProperty = connector.propertyFactory().create(JcrLexicon.MIMETYPE, mimeType);
connectorChangeSet.propertyAdded(contentId, JcrNtLexicon.RESOURCE, Collections.<Name>emptySet(),
contentId, mimeTypeProperty, queryable);
} catch (Throwable e) {
connector.getLogger().error(e, JcrI18n.couldNotGetMimeType, connector.getSourceName(), contentId,
e.getMessage());
}
}
} catch (Exception e) {
connector.log().warn("Cannot get binary value for '{0}'", resolvedPath);
}
// fire PROPERTY_ADDED for nt:file/jcr:content/jcr:lastModified
Property lastModified = connector.propertyFactory().create(JcrLexicon.LAST_MODIFIED,
connector.lastModifiedTimeFor(file));
connectorChangeSet.propertyAdded(contentId, JcrNtLexicon.RESOURCE, Collections.<Name>emptySet(), contentId,
lastModified, queryable);
if (owner != null) {
// fire PROPERTY_ADDED for nt:file/jcr:content/jcr:lastModifiedBy
Property lastModifiedBy = connector.propertyFactory().create(JcrLexicon.LAST_MODIFIED_BY, owner);
connectorChangeSet.propertyAdded(contentId, JcrNtLexicon.RESOURCE, Collections.<Name>emptySet(), contentId,
lastModifiedBy, queryable);
}
}
}