git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/data-access/storagehub-webapp/1.0@177327 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
85a2b7cf41
commit
5271923cee
|
@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class AccountingHandler {
|
public class AccountingHandler {
|
||||||
|
|
||||||
|
private static final String VERSION_ACCOUNTING= "hl:version";
|
||||||
private static final String USER = "hl:user";
|
private static final String USER = "hl:user";
|
||||||
private static final String DATE = "hl:date";
|
private static final String DATE = "hl:date";
|
||||||
private static final String ITEM_NAME = "hl:itemName";
|
private static final String ITEM_NAME = "hl:itemName";
|
||||||
|
@ -38,14 +39,13 @@ public class AccountingHandler {
|
||||||
|
|
||||||
public void createReadObj(String title, Session ses, Node node, boolean saveHistory ) {
|
public void createReadObj(String title, Session ses, Node node, boolean saveHistory ) {
|
||||||
try {
|
try {
|
||||||
Node directoryNode = node.getParent();
|
|
||||||
|
|
||||||
if (!directoryNode.hasNode(NodeProperty.ACCOUNTING.toString())){
|
if (!node.hasNode(NodeProperty.ACCOUNTING.toString())){
|
||||||
directoryNode.addNode(NodeProperty.ACCOUNTING.toString(), NodeProperty.NT_ACCOUNTING.toString());
|
node.addNode(NodeProperty.ACCOUNTING.toString(), NodeProperty.NT_ACCOUNTING.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Node accountingNodeParent = directoryNode.getNode(NodeProperty.ACCOUNTING.toString());
|
Node accountingNodeParent = node.getNode(NodeProperty.ACCOUNTING.toString());
|
||||||
Node accountingNode = accountingNodeParent.addNode(UUID.randomUUID().toString(),AccountingEntryType.READ.getNodeTypeDefinition());
|
Node accountingNode = accountingNodeParent.addNode(UUID.randomUUID().toString(),AccountingEntryType.READ.getNodeTypeDefinition());
|
||||||
accountingNode.setProperty(USER, AuthorizationProvider.instance.get().getClient().getId());
|
accountingNode.setProperty(USER, AuthorizationProvider.instance.get().getClient().getId());
|
||||||
accountingNode.setProperty(DATE, Calendar.getInstance());
|
accountingNode.setProperty(DATE, Calendar.getInstance());
|
||||||
|
@ -60,7 +60,7 @@ public class AccountingHandler {
|
||||||
version = versions.nextVersion();
|
version = versions.nextVersion();
|
||||||
}
|
}
|
||||||
if (version!=null)
|
if (version!=null)
|
||||||
accountingNode.setProperty("hl:version", version.getName());
|
accountingNode.setProperty(VERSION_ACCOUNTING, version.getName());
|
||||||
}catch(UnsupportedRepositoryOperationException uropex) {
|
}catch(UnsupportedRepositoryOperationException uropex) {
|
||||||
logger.warn("version cannot be retrieved", uropex);
|
logger.warn("version cannot be retrieved", uropex);
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,41 @@ public class AccountingHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void createFileUpdated(String title, Session ses, Node node, boolean saveHistory ) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (!node.hasNode(NodeProperty.ACCOUNTING.toString())){
|
||||||
|
node.addNode(NodeProperty.ACCOUNTING.toString(), NodeProperty.NT_ACCOUNTING.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Node accountingNodeParent = node.getNode(NodeProperty.ACCOUNTING.toString());
|
||||||
|
Node accountingNode = accountingNodeParent.addNode(UUID.randomUUID().toString(),AccountingEntryType.UPDATE.getNodeTypeDefinition());
|
||||||
|
|
||||||
|
accountingNode.setProperty(USER, AuthorizationProvider.instance.get().getClient().getId());
|
||||||
|
accountingNode.setProperty(DATE, Calendar.getInstance());
|
||||||
|
accountingNode.setProperty(ITEM_NAME, title);
|
||||||
|
|
||||||
|
try {
|
||||||
|
VersionManager vManager = ses.getWorkspace().getVersionManager();
|
||||||
|
VersionHistory history = vManager.getVersionHistory(node.getNode("jcr:content").getPath());
|
||||||
|
VersionIterator versions = history.getAllVersions();
|
||||||
|
Version version= null;
|
||||||
|
while (versions.hasNext()) {
|
||||||
|
version = versions.nextVersion();
|
||||||
|
}
|
||||||
|
if (version!=null)
|
||||||
|
accountingNode.setProperty(VERSION_ACCOUNTING, version.getName());
|
||||||
|
}catch(UnsupportedRepositoryOperationException uropex) {
|
||||||
|
logger.warn("version cannot be retrieved", uropex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (saveHistory) ses.save();
|
||||||
|
} catch (RepositoryException e) {
|
||||||
|
logger.warn("error trying to retrieve accountign node",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void createFolderAddObj(String title, String itemType, String mimeType, Session ses, Node node, boolean saveHistory ) {
|
public void createFolderAddObj(String title, String itemType, String mimeType, Session ses, Node node, boolean saveHistory ) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -296,13 +296,15 @@ public class ItemsCreator {
|
||||||
versionHandler.checkoutContentNode(newNode, ses);
|
versionHandler.checkoutContentNode(newNode, ses);
|
||||||
log.trace("replacing content of class {}",item.getContent().getClass());
|
log.trace("replacing content of class {}",item.getContent().getClass());
|
||||||
item2Node.replaceContent(newNode,item, ItemAction.UPDATED);
|
item2Node.replaceContent(newNode,item, ItemAction.UPDATED);
|
||||||
|
accountingHandler.createFileUpdated(item.getTitle(), ses, newNode, false);
|
||||||
}catch(PathNotFoundException pnf) {
|
}catch(PathNotFoundException pnf) {
|
||||||
authChecker.checkWriteAuthorizationControl(ses, destinationNode.getIdentifier(), true);
|
authChecker.checkWriteAuthorizationControl(ses, destinationNode.getIdentifier(), true);
|
||||||
newNode = item2Node.getNode(destinationNode, item);
|
newNode = item2Node.getNode(destinationNode, item);
|
||||||
versionHandler.makeVersionableContent(newNode, ses);
|
versionHandler.makeVersionableContent(newNode, ses);
|
||||||
|
accountingHandler.createFolderAddObj(name, item.getClass().getSimpleName(), item.getContent().getMimeType(), ses, newNode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
accountingHandler.createFolderAddObj(name, item.getClass().getSimpleName(), item.getContent().getMimeType(), ses, newNode, false);
|
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue