001package org.kuali.ole.docstore.repository;
002
003import javax.jcr.Node;
004import javax.jcr.Property;
005import javax.jcr.Session;
006
007import org.kuali.ole.docstore.OleDocStoreException;
008import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
009import org.slf4j.Logger;
010import org.slf4j.LoggerFactory;
011
012import static org.kuali.ole.docstore.process.ProcessParameters.FILE;
013import static org.kuali.ole.docstore.process.ProcessParameters.NODE_LEVEL1;
014import static org.kuali.ole.docstore.process.ProcessParameters.NODE_LEVEL2;
015import static org.kuali.ole.docstore.process.ProcessParameters.NODE_LEVEL3;
016
017/**
018 * User: tirumalesh.b
019 * Date: 31/8/12 Time: 5:31 PM
020 */
021public class WorkBibNodeManager
022        extends CustomNodeManager
023        implements NodeManager {
024    private static WorkBibNodeManager ourInstance = new WorkBibNodeManager();
025    private static final Logger LOG = LoggerFactory.getLogger(WorkBibNodeManager.class);
026
027
028    //protected NodeManager nodeManager;
029
030    private WorkBibNodeManager() {
031        super();
032        numLevels = 3;
033        //nodeManager = CustomNodeManager.getInstance();
034    }
035
036    public static WorkBibNodeManager getInstance() {
037        return ourInstance;
038    }
039
040    @Override
041    public void linkNodes(Node bibNode, Node instanceNode, Session session) throws OleDocStoreException {
042        try {
043            if (instanceNode.hasProperty("bibIdentifier")) {
044                String bibId = instanceNode.getProperty("bibIdentifier").getString();
045                bibId = bibId + "," + bibNode.getIdentifier();
046                instanceNode.setProperty("bibIdentifier", bibId);
047            } else {
048                instanceNode.setProperty("bibIdentifier", bibNode.getIdentifier());
049            }
050            if (bibNode.hasProperty("instanceIdentifier")) {
051                String instId = bibNode.getProperty("instanceIdentifier").getString();
052                instId = instId + "," + instanceNode.getIdentifier();
053                bibNode.setProperty("instanceIdentifier", instId);
054            } else {
055                bibNode.setProperty("instanceIdentifier", instanceNode.getIdentifier());
056            }
057
058        } catch (Exception e) {
059            throw new OleDocStoreException(e);
060        }
061    }
062
063    public String getParentNodePath() {
064        return "/work/bib";
065    }
066
067
068}