final org.uberfire.java.nio.file.Path path = Paths.convert( resource );
final DublinCoreView dcoreView = ioService.getFileAttributeView( path, DublinCoreView.class );
final DiscussionView discussView = ioService.getFileAttributeView( path, DiscussionView.class );
final OtherMetaView otherMetaView = ioService.getFileAttributeView( path, OtherMetaView.class );
final VersionAttributeView versionAttributeView = ioService.getFileAttributeView( path, VersionAttributeView.class );
return MetadataBuilder.newMetadata()
.withPath( Paths.convert( path.toRealPath() ) )
.withCheckinComment( versionAttributeView.readAttributes().history().records().size() > 0 ? versionAttributeView.readAttributes().history().records().get( versionAttributeView.readAttributes().history().records().size() - 1 ).comment() : null )
.withLastContributor( versionAttributeView.readAttributes().history().records().size() > 0 ? versionAttributeView.readAttributes().history().records().get( versionAttributeView.readAttributes().history().records().size() - 1 ).author() : null )
.withCreator( versionAttributeView.readAttributes().history().records().size() > 0 ? versionAttributeView.readAttributes().history().records().get( 0 ).author() : null )
.withLastModified( new Date( versionAttributeView.readAttributes().lastModifiedTime().toMillis() ) )
.withDateCreated( new Date( versionAttributeView.readAttributes().creationTime().toMillis() ) )
.withSubject( dcoreView.readAttributes().subjects().size() > 0 ? dcoreView.readAttributes().subjects().get( 0 ) : null )
.withType( dcoreView.readAttributes().types().size() > 0 ? dcoreView.readAttributes().types().get( 0 ) : null )
.withExternalRelation( dcoreView.readAttributes().relations().size() > 0 ? dcoreView.readAttributes().relations().get( 0 ) : null )
.withExternalSource( dcoreView.readAttributes().sources().size() > 0 ? dcoreView.readAttributes().sources().get( 0 ) : null )
.withDescription( dcoreView.readAttributes().descriptions().size() > 0 ? dcoreView.readAttributes().descriptions().get( 0 ) : null )
.withCategories( otherMetaView.readAttributes().categories() )
.withDiscussion( discussView.readAttributes().discussion() )
.withVersion( new ArrayList<VersionRecord>( versionAttributeView.readAttributes().history().records().size() ) {{
for ( final VersionRecord record : versionAttributeView.readAttributes().history().records() ) {
add( new PortableVersionRecord( record.id(), record.author(), record.email(), record.comment(), record.date(), record.uri() ) );
}
}} )
.build();