2018-05-17 12:51:56 +02:00
|
|
|
package org.gcube.data.access.storagehub;
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
2019-07-29 16:26:08 +02:00
|
|
|
import java.net.URL;
|
2018-05-17 12:51:56 +02:00
|
|
|
import java.security.MessageDigest;
|
|
|
|
import java.util.ArrayList;
|
2018-10-25 16:33:23 +02:00
|
|
|
import java.util.Calendar;
|
2018-05-17 12:51:56 +02:00
|
|
|
import java.util.Deque;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2018-10-25 16:33:23 +02:00
|
|
|
import java.util.Set;
|
2018-05-17 12:51:56 +02:00
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
|
|
import javax.jcr.Node;
|
|
|
|
import javax.jcr.NodeIterator;
|
2018-10-25 16:33:23 +02:00
|
|
|
import javax.jcr.PathNotFoundException;
|
|
|
|
import javax.jcr.RepositoryException;
|
2018-05-17 12:51:56 +02:00
|
|
|
import javax.jcr.Session;
|
2019-04-01 17:50:43 +02:00
|
|
|
import javax.jcr.lock.Lock;
|
|
|
|
import javax.jcr.lock.LockException;
|
2018-10-25 16:33:23 +02:00
|
|
|
import javax.jcr.version.Version;
|
2018-05-17 12:51:56 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
|
import org.apache.jackrabbit.util.Text;
|
2018-05-17 12:51:56 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
2018-10-25 16:33:23 +02:00
|
|
|
import org.gcube.common.storagehub.model.Excludes;
|
2018-05-17 12:51:56 +02:00
|
|
|
import org.gcube.common.storagehub.model.Paths;
|
2018-10-25 16:33:23 +02:00
|
|
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
2019-04-01 17:50:43 +02:00
|
|
|
import org.gcube.common.storagehub.model.exceptions.ItemLockedException;
|
2018-05-17 12:51:56 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
2019-07-29 16:26:08 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.ExternalLink;
|
2018-05-17 12:51:56 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
2018-10-25 16:33:23 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.GCubeItem;
|
2018-05-17 12:51:56 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
2018-06-29 16:59:24 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.SharedFolder;
|
2018-10-25 16:33:23 +02:00
|
|
|
import org.gcube.common.storagehub.model.types.ItemAction;
|
2018-05-17 12:51:56 +02:00
|
|
|
import org.gcube.common.storagehub.model.types.NodeProperty;
|
|
|
|
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
|
|
|
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
|
|
|
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
|
|
|
import org.gcube.data.access.storagehub.accounting.AccountingHandler;
|
2018-10-25 16:33:23 +02:00
|
|
|
import org.gcube.data.access.storagehub.handlers.Item2NodeConverter;
|
|
|
|
import org.gcube.data.access.storagehub.handlers.Node2ItemConverter;
|
2019-07-05 12:09:16 +02:00
|
|
|
import org.gcube.data.access.storagehub.handlers.StorageBackendHandler;
|
2018-10-25 16:33:23 +02:00
|
|
|
import org.gcube.data.access.storagehub.handlers.VersionHandler;
|
2019-07-05 12:09:16 +02:00
|
|
|
import org.gcube.data.access.storagehub.storage.backend.impl.GCubeStorageBackend;
|
2018-05-17 12:51:56 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
public class Utils {
|
|
|
|
|
|
|
|
public final static String SERVICE_NAME = "home-library";
|
|
|
|
public final static String SERVICE_CLASS = "org.gcube.portlets.user";
|
|
|
|
private static final String FOLDERS_TYPE = "nthl:workspaceItem";
|
2018-10-25 16:33:23 +02:00
|
|
|
|
2018-05-17 12:51:56 +02:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(Utils.class);
|
|
|
|
|
|
|
|
public static String getSecurePassword(String user) throws Exception {
|
|
|
|
String digest = null;
|
|
|
|
try {
|
|
|
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
|
byte[] hash = md.digest(user.getBytes("UTF-8"));
|
|
|
|
|
|
|
|
//converting byte array to Hexadecimal String
|
|
|
|
StringBuilder sb = new StringBuilder(2*hash.length);
|
|
|
|
for(byte b : hash){
|
|
|
|
sb.append(String.format("%02x", b&0xff));
|
|
|
|
}
|
|
|
|
digest = sb.toString();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("error getting secure password",e);
|
|
|
|
}
|
|
|
|
return digest;
|
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
|
|
|
|
public static long getItemCount(Node parent, boolean showHidden, Class<? extends Item> nodeType) throws RepositoryException, BackendGenericError{
|
|
|
|
return getItemList(parent, Excludes.ALL, null, showHidden, nodeType).size();
|
2018-05-17 12:51:56 +02:00
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
|
|
|
|
|
2019-04-01 17:50:43 +02:00
|
|
|
public static void acquireLockWithWait(Session ses, String nodePath, boolean isDeep, String login, int maxTries) throws RepositoryException, ItemLockedException {
|
|
|
|
|
|
|
|
Lock lock = null;
|
|
|
|
int tries = 0;
|
|
|
|
while(lock==null && tries<=maxTries) {
|
|
|
|
try {
|
|
|
|
lock = ses.getWorkspace().getLockManager().lock(nodePath, isDeep, true, 0,login);
|
|
|
|
logger.info("lock acquired(try n. {})", tries);
|
|
|
|
}catch (LockException e) {
|
|
|
|
try {
|
|
|
|
if (maxTries>=tries) {
|
|
|
|
int waitTime = (int)(Math.random()*5000);
|
|
|
|
logger.info("lock NOT acquired, waiting (try n. {}) for {}", tries, waitTime);
|
|
|
|
Thread.sleep(waitTime);
|
|
|
|
}
|
|
|
|
} catch (InterruptedException e1) {}
|
|
|
|
tries++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lock==null) throw new ItemLockedException("the item is locked");
|
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static <T extends Item> List<T> getItemList(Node parent, List<String> excludes, Range range, boolean showHidden, Class<? extends Item> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
2018-05-17 12:51:56 +02:00
|
|
|
|
2018-12-28 17:58:08 +01:00
|
|
|
logger.debug("getting children of node {}", parent.getIdentifier());
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-05-17 12:51:56 +02:00
|
|
|
List<T> returnList = new ArrayList<T>();
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
NodeIterator iterator = parent.getNodes();
|
|
|
|
logger.trace("time to get iterator {}",(System.currentTimeMillis()-start));
|
2018-10-25 16:33:23 +02:00
|
|
|
logger.trace("nodeType is {}",nodeTypeToInclude);
|
2018-05-17 12:51:56 +02:00
|
|
|
int count =0;
|
|
|
|
logger.trace("selected range is {}", range);
|
2018-10-25 16:33:23 +02:00
|
|
|
Node2ItemConverter node2Item= new Node2ItemConverter();
|
2018-05-17 12:51:56 +02:00
|
|
|
while (iterator.hasNext()){
|
|
|
|
Node current = iterator.nextNode();
|
2018-10-25 16:33:23 +02:00
|
|
|
|
2018-12-28 17:58:08 +01:00
|
|
|
logger.debug("current node "+current.getName());
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-05-17 12:51:56 +02:00
|
|
|
if (isToExclude(current, showHidden))
|
|
|
|
continue;
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-12-28 17:58:08 +01:00
|
|
|
logger.debug("current node not excluded "+current.getName());
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-05-17 12:51:56 +02:00
|
|
|
if (range==null || (count>=range.getStart() && returnList.size()<range.getLimit())) {
|
2018-10-25 16:33:23 +02:00
|
|
|
T item = node2Item.getFilteredItem(current, excludes, nodeTypeToInclude);
|
|
|
|
if (item==null) continue;
|
2018-05-17 12:51:56 +02:00
|
|
|
returnList.add(item);
|
|
|
|
}
|
|
|
|
count++;
|
2018-10-25 16:33:23 +02:00
|
|
|
|
2018-05-17 12:51:56 +02:00
|
|
|
}
|
|
|
|
return returnList;
|
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
|
|
|
|
private static boolean isToExclude(Node node, boolean showHidden) throws RepositoryException{
|
2018-05-17 12:51:56 +02:00
|
|
|
return ((node.getName().startsWith("rep:") || (node.getName().startsWith("hl:"))) ||
|
2018-10-25 16:33:23 +02:00
|
|
|
(!showHidden && node.hasProperty(NodeProperty.HIDDEN.toString()) && node.getProperty(NodeProperty.HIDDEN.toString()).getBoolean()) ||
|
|
|
|
(node.getPrimaryNodeType().getName().equals(FOLDERS_TYPE) && Constants.FOLDERS_TO_EXLUDE.contains(node.getName())));
|
2018-05-17 12:51:56 +02:00
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
|
2018-12-17 14:55:43 +01:00
|
|
|
public static org.gcube.common.storagehub.model.Path getWorkspacePath(){
|
2018-05-17 12:51:56 +02:00
|
|
|
return Paths.getPath(String.format("/Home/%s/Workspace",AuthorizationProvider.instance.get().getClient().getId()));
|
|
|
|
}
|
|
|
|
|
2018-12-17 14:55:43 +01:00
|
|
|
public static org.gcube.common.storagehub.model.Path getWorkspacePath(String login){
|
2018-06-29 16:59:24 +02:00
|
|
|
return Paths.getPath(String.format("/Home/%s/Workspace",login));
|
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
|
2018-12-17 14:55:43 +01:00
|
|
|
public static org.gcube.common.storagehub.model.Path getHome(String login){
|
|
|
|
return Paths.getPath(String.format("/Home/%s",login));
|
|
|
|
}
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
public static Deque<Item> getAllNodesForZip(FolderItem directory, Session session, AccountingHandler accountingHandler, List<String> excludes) throws RepositoryException, BackendGenericError{
|
2018-05-17 12:51:56 +02:00
|
|
|
Deque<Item> queue = new LinkedList<Item>();
|
|
|
|
Node currentNode = session.getNodeByIdentifier(directory.getId());
|
|
|
|
queue.push(directory);
|
|
|
|
Deque<Item> tempQueue = new LinkedList<Item>();
|
2018-10-25 16:33:23 +02:00
|
|
|
logger.debug("adding directory {}",currentNode.getPath());
|
|
|
|
for (Item item : Utils.getItemList(currentNode,Excludes.GET_ONLY_CONTENT, null, false, null)){
|
|
|
|
if (excludes.contains(item.getId())) continue;
|
2018-05-17 12:51:56 +02:00
|
|
|
if (item instanceof FolderItem)
|
2018-10-25 16:33:23 +02:00
|
|
|
tempQueue.addAll(getAllNodesForZip((FolderItem) item, session, accountingHandler, excludes));
|
2018-05-17 12:51:56 +02:00
|
|
|
else if (item instanceof AbstractFileItem){
|
|
|
|
logger.debug("adding file {}",item.getPath());
|
|
|
|
AbstractFileItem fileItem = (AbstractFileItem) item;
|
|
|
|
accountingHandler.createReadObj(fileItem.getTitle(), session, session.getNodeByIdentifier(item.getId()), false);
|
|
|
|
queue.addLast(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
queue.addAll(tempQueue);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-05 12:09:16 +02:00
|
|
|
public static void zipNode(ZipOutputStream zos, Deque<Item> queue, String login, org.gcube.common.storagehub.model.Path originalPath, StorageBackendHandler storageHandler) throws Exception{
|
2018-05-17 12:51:56 +02:00
|
|
|
logger.trace("originalPath is {}",originalPath.toPath());
|
|
|
|
org.gcube.common.storagehub.model.Path actualPath = Paths.getPath("");
|
|
|
|
while (!queue.isEmpty()) {
|
|
|
|
Item item = queue.pop();
|
|
|
|
if (item instanceof FolderItem) {
|
|
|
|
actualPath = Paths.getPath(item.getPath());
|
2018-10-25 16:33:23 +02:00
|
|
|
logger.debug("actualPath is {}",actualPath.toPath());
|
2018-05-17 12:51:56 +02:00
|
|
|
String name = Paths.remove(actualPath, originalPath).toPath().replaceFirst("/", "");
|
2018-10-25 16:33:23 +02:00
|
|
|
logger.debug("writing dir {}",name);
|
|
|
|
if (name.isEmpty()) continue;
|
|
|
|
try {
|
2018-05-17 12:51:56 +02:00
|
|
|
zos.putNextEntry(new ZipEntry(name));
|
2018-10-25 16:33:23 +02:00
|
|
|
}finally {
|
2018-05-17 12:51:56 +02:00
|
|
|
zos.closeEntry();
|
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
} else if (item instanceof AbstractFileItem){
|
|
|
|
try {
|
2019-07-05 12:09:16 +02:00
|
|
|
InputStream streamToWrite = storageHandler.download(((AbstractFileItem)item).getContent().getStorageId());
|
2018-10-25 16:33:23 +02:00
|
|
|
if (streamToWrite == null){
|
|
|
|
logger.warn("discarding item {} ",item.getName());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
try(BufferedInputStream is = new BufferedInputStream(streamToWrite)){
|
|
|
|
String name = (Paths.remove(actualPath, originalPath).toPath()+item.getName()).replaceFirst("/", "");
|
|
|
|
logger.debug("writing file {}",name);
|
|
|
|
zos.putNextEntry(new ZipEntry(name));
|
|
|
|
copyStream(is, zos);
|
|
|
|
}catch (Exception e) {
|
|
|
|
logger.warn("error writing item {}", item.getName(),e);
|
|
|
|
} finally{
|
|
|
|
zos.closeEntry();
|
|
|
|
}
|
|
|
|
zos.flush();
|
|
|
|
}catch (Throwable e) {
|
|
|
|
logger.warn("error reading content for item {}", item.getPath(),e);
|
|
|
|
}
|
2018-05-17 12:51:56 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
zos.close();
|
2018-05-17 12:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void copyStream(InputStream in, OutputStream out) throws IOException {
|
|
|
|
byte[] buffer = new byte[2048];
|
|
|
|
int readcount = 0;
|
|
|
|
while ((readcount=in.read(buffer))!=-1) {
|
|
|
|
out.write(buffer, 0, readcount);
|
|
|
|
}
|
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
public static boolean hasSharedChildren(Node node) throws RepositoryException, BackendGenericError{
|
|
|
|
Node2ItemConverter node2Item = new Node2ItemConverter();
|
|
|
|
NodeIterator children = node.getNodes();
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
while (children.hasNext()) {
|
|
|
|
Node child= children.nextNode();
|
|
|
|
if (node2Item.checkNodeType(child, SharedFolder.class)) return true;
|
|
|
|
if (node2Item.checkNodeType(child, FolderItem.class) && hasSharedChildren(child)) return true;
|
2018-06-29 16:59:24 +02:00
|
|
|
}
|
|
|
|
return false;
|
2018-10-25 16:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void getAllContentIds(Session ses, Set<String> idsToDelete, Item itemToDelete, VersionHandler versionHandler) throws Exception{
|
|
|
|
if (itemToDelete instanceof AbstractFileItem) {
|
|
|
|
List<Version> versions = versionHandler.getContentVersionHistory(ses.getNodeByIdentifier(itemToDelete.getId()), ses);
|
|
|
|
|
|
|
|
versions.forEach(v -> {
|
|
|
|
try {
|
|
|
|
String storageId =v.getFrozenNode().getProperty(NodeProperty.STORAGE_ID.toString()).getString();
|
|
|
|
idsToDelete.add(storageId);
|
|
|
|
logger.info("retrieved StorageId {} for version {}", storageId, v.getName());
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.warn("error retreiving sotrageId version for item with id {}",itemToDelete.getId(),e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
idsToDelete.add(((AbstractFileItem) itemToDelete).getContent().getStorageId());
|
|
|
|
}else if (itemToDelete instanceof FolderItem) {
|
|
|
|
List<Item> items = Utils.getItemList(ses.getNodeByIdentifier(itemToDelete.getId()), Excludes.GET_ONLY_CONTENT , null, true, null);
|
|
|
|
for (Item item: items)
|
|
|
|
getAllContentIds(ses, idsToDelete, item, versionHandler);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
public static String checkExistanceAndGetUniqueName(Session ses, Node destination, String name) throws BackendGenericError{
|
|
|
|
try {
|
|
|
|
destination.getNode(name);
|
|
|
|
}catch(PathNotFoundException pnf) {
|
|
|
|
return Text.escapeIllegalJcrChars(name);
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new BackendGenericError(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
String filename = FilenameUtils.getBaseName(name);
|
|
|
|
String ext = FilenameUtils.getExtension(name);
|
|
|
|
|
|
|
|
String nameTocheck = ext.isEmpty()? String.format("%s(*)",filename): String.format("%s(*).%s",filename, ext);
|
|
|
|
|
|
|
|
logger.debug("filename is {}, extension is {} , and name to check is {}", filename, ext, nameTocheck);
|
|
|
|
|
|
|
|
NodeIterator ni = destination.getNodes(nameTocheck);
|
|
|
|
int maxval = 0;
|
|
|
|
while (ni.hasNext()) {
|
|
|
|
Node n = ni.nextNode();
|
|
|
|
int actual = Integer.parseInt(n.getName().replaceAll(String.format("%s\\((\\d*)\\).*", filename), "$1"));
|
|
|
|
if (actual>maxval)
|
|
|
|
maxval = actual;
|
|
|
|
}
|
|
|
|
|
2018-06-29 16:59:24 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
String newName = ext.isEmpty()? String.format("%s(%d)", filename,maxval+1) : String.format("%s(%d).%s", filename,maxval+1, ext) ;
|
|
|
|
return Text.escapeIllegalJcrChars(newName);
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new BackendGenericError(e);
|
|
|
|
}
|
|
|
|
}
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-11-30 17:49:35 +01:00
|
|
|
public static Node createFolderInternally(Session ses, Node destinationNode, String name, String description, boolean hidden, String login, AccountingHandler accountingHandler) throws BackendGenericError {
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
String uniqueName = Utils.checkExistanceAndGetUniqueName(ses, destinationNode, name);
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
FolderItem item = new FolderItem();
|
|
|
|
Calendar now = Calendar.getInstance();
|
|
|
|
item.setName(uniqueName);
|
|
|
|
item.setTitle(uniqueName);
|
|
|
|
item.setDescription(description);
|
|
|
|
//item.setCreationTime(now);
|
2018-11-30 17:49:35 +01:00
|
|
|
item.setHidden(hidden);
|
2018-10-25 16:33:23 +02:00
|
|
|
item.setLastAction(ItemAction.CREATED);
|
|
|
|
item.setLastModificationTime(now);
|
|
|
|
item.setLastModifiedBy(login);
|
|
|
|
item.setOwner(login);
|
|
|
|
item.setPublicItem(false);
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
//to inherit hidden property
|
|
|
|
//item.setHidden(destinationItem.isHidden());
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2019-02-14 12:01:59 +01:00
|
|
|
Node newNode = new Item2NodeConverter().getNode(destinationNode, item);
|
2018-11-30 17:49:35 +01:00
|
|
|
if (accountingHandler!=null)
|
|
|
|
accountingHandler.createFolderAddObj(name, item.getClass().getSimpleName(), null, ses, newNode, false);
|
2018-10-25 16:33:23 +02:00
|
|
|
return newNode;
|
|
|
|
}
|
2019-07-29 16:26:08 +02:00
|
|
|
|
|
|
|
public static Node createURLInternally(Session ses, Node destinationNode, String name, URL value, String description, String login, AccountingHandler accountingHandler) throws BackendGenericError {
|
|
|
|
|
|
|
|
String uniqueName = Utils.checkExistanceAndGetUniqueName(ses, destinationNode, name);
|
|
|
|
|
|
|
|
ExternalLink item = new ExternalLink();
|
|
|
|
Calendar now = Calendar.getInstance();
|
|
|
|
item.setName(uniqueName);
|
|
|
|
item.setTitle(uniqueName);
|
|
|
|
item.setDescription(description);
|
|
|
|
//item.setCreationTime(now);
|
|
|
|
item.setLastAction(ItemAction.CREATED);
|
|
|
|
item.setLastModificationTime(now);
|
|
|
|
item.setLastModifiedBy(login);
|
|
|
|
item.setOwner(login);
|
|
|
|
item.setPublicItem(false);
|
|
|
|
item.setValue(value);
|
|
|
|
|
|
|
|
//to inherit hidden property
|
|
|
|
//item.setHidden(destinationItem.isHidden());
|
|
|
|
|
|
|
|
Node newNode = new Item2NodeConverter().getNode(destinationNode, item);
|
|
|
|
if (accountingHandler!=null)
|
|
|
|
accountingHandler.createFolderAddObj(name, item.getClass().getSimpleName(), null, ses, newNode, false);
|
|
|
|
return newNode;
|
|
|
|
}
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
public static Node createGcubeItemInternally(Session ses, Node destinationNode, String name, String description, String login, GCubeItem gcubeItem, AccountingHandler accountingHandler) throws BackendGenericError {
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
Calendar now = Calendar.getInstance();
|
|
|
|
gcubeItem.setName(name);
|
|
|
|
gcubeItem.setTitle(name);
|
|
|
|
gcubeItem.setDescription(description);
|
|
|
|
//item.setCreationTime(now);
|
|
|
|
gcubeItem.setHidden(false);
|
|
|
|
gcubeItem.setLastAction(ItemAction.CREATED);
|
|
|
|
gcubeItem.setLastModificationTime(now);
|
|
|
|
gcubeItem.setLastModifiedBy(login);
|
|
|
|
gcubeItem.setOwner(login);
|
|
|
|
//to inherit hidden property
|
|
|
|
//item.setHidden(destinationItem.isHidden());
|
|
|
|
|
2019-02-14 12:01:59 +01:00
|
|
|
Node newNode = new Item2NodeConverter().getNode(destinationNode, gcubeItem);
|
2018-10-25 16:33:23 +02:00
|
|
|
//TODO: accounting for GCUBEITEM
|
|
|
|
//accountingHandler.createFolderAddObj(name, item.getClass().getSimpleName(), null, ses, newNode, false);
|
|
|
|
return newNode;
|
|
|
|
}
|
2019-04-01 17:50:43 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
public static void setPropertyOnChangeNode(Node node, String login, ItemAction action) throws RepositoryException {
|
|
|
|
node.setProperty(NodeProperty.LAST_MODIFIED.toString(), Calendar.getInstance());
|
|
|
|
node.setProperty(NodeProperty.LAST_MODIFIED_BY.toString(), login);
|
|
|
|
node.setProperty(NodeProperty.LAST_ACTION.toString(), action.name());
|
2018-06-29 16:59:24 +02:00
|
|
|
}
|
2018-05-17 12:51:56 +02:00
|
|
|
}
|