Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.openl.rules.repository.jcr;
  
 
 import javax.jcr.Node;
 
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 public class JcrProductionRepository extends BaseJcrRepository implements RProductionRepository {
     private final Log log = LogFactory.getLog(JcrProductionRepository.class);
 
     public static class JCR_SQL2QueryBuilder{
         private boolean firstCondition = true;
 
         private void appendDateCondition(String propertyNameDate dateString conditionStringBuilder sb) {
             if (date != null) {
                 if(){
                      = false;
                     sb.append(" WHERE ");
                 }else{
                     sb.append(" AND ");
                 }
 
                 sb.append('[').append(propertyName).append(']').append(condition).append(getDateString(datecondition));
             }
         }
 
         private String getDateString(Date dateString condition) {
             DateFormat format = null;
             
             if (condition.indexOf(">") > -1) {
                 format = new SimpleDateFormat("yyyy-MM-dd'T'00:00:00.000'Z'");
             } else if (condition.indexOf("<") > -1) {
                 format = new SimpleDateFormat("yyyy-MM-dd'T'23:59:59.999'Z'");
             } else {
                 format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
             }
 
             String dateString = format.format(date);
 
             StringBuilder sb = new StringBuilder();
 
             sb.append("CAST('").append(dateString).append("' AS DATE)");
             return sb.toString();
         }
 
         public String buildQuery(SearchParams params) {
             StringBuilder sb = new StringBuilder("SELECT * FROM [nt:base]");
             if (!StringUtils.isEmpty(params.getLineOfBusiness())) {
                 if(){
                      = false;
                     sb.append(" WHERE ");
                 }else{
                     sb.append(" AND ");
                 }
                 // todo: check for injection
                 sb.append("[" + . + "]").append("=\"").append(params.getLineOfBusiness()).append("\"");
             }
 
             appendDateCondition(.params.getLowerEffectiveDate(), ">="sb);
             appendDateCondition(.params.getUpperEffectiveDate(), "<="sb);
             appendDateCondition(.params.getLowerExpirationDate(), ">="sb);
             appendDateCondition(.params.getUpperExpirationDate(), "<="sb);
 
             return sb.toString();
         }
     }
 
     final static String PROPERTY_NOTIFICATION = "deploymentReady";
    public static final String DEPLOY_ROOT = "/deploy";
    private Node deployLocation;
    public JcrProductionRepository(String nameSession sessionRTransactionManager transactionManagerthrows RepositoryException {
        super(namesessiontransactionManager);
        if (.isNew()) {
            session.save();
        }
                nullnullfalse);
    }
    public synchronized void addListener(RDeploymentListener listenerthrows RRepositoryException {
        .add(listener);
    }
    @Deprecated
        throw new UnsupportedOperationException();
    }
    @Deprecated
        try {
            return JcrProductionDeployment.createDeployment(name);
        } catch (RepositoryException e) {
            throw new RRepositoryException("could not create deployment {0}"ename);
        }
    }

    
Creates a project in the repository. Name of new project must be unique.

Parameters:
name name of new project
Returns:
newly created project
Throws:
org.openl.rules.repository.exceptions.RRepositoryException if failed
    @Deprecated
    public RProject createProject(String namethrows RRepositoryException {
        throw new UnsupportedOperationException();
    }
        try {
            Query query = getSession().getWorkspace().getQueryManager().createQuery(new JCR_SQL2QueryBuilder().buildQuery(params), .);
            QueryResult queryResult = query.execute();
            NodeIterator nodeIterator = queryResult.getNodes();
            List<ArtefactAPIresult = new ArrayList<ArtefactAPI>();
            while (nodeIterator.hasNext()) {
                Node node = nodeIterator.nextNode();
                ArtefactPath path = new ArtefactPathImpl(new String[] { node.getName() });
                String type = node.getPrimaryNodeType().getName();
                if (type.equals(.)) {
                    result.add(new JcrFolderAPI(nodegetTransactionManager(), path));
                } else if (type.equals(.)) {
                    result.add(new JcrFolderAPI(nodegetTransactionManager(), path));
                } else if (type.equals(.)) {
                    result.add(new JcrFileAPI(nodegetTransactionManager(), pathfalse));
                }
            }
            return result;
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to run query"e);
        }
    }
    @Deprecated
        throw new UnsupportedOperationException();
    }
    @Deprecated
        throw new UnsupportedOperationException();
    }
    @Deprecated
        Node node;
        try {
            node = .getNode(name);
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to get node"e);
        }
        try {
            return new JcrProductionDeployment(node);
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to wrap JCR node"e);
        }
    }
        List<Stringresult = new ArrayList<String>();
        try {
            NodeIterator iterator = .getNodes();
            while (iterator.hasNext()) {
                Node node = iterator.nextNode();
                if (node.getPrimaryNodeType().getName().equals(.)) {
                    result.add(node.getName());
                }
            }
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to enumerate deployments"e);
        }
        return result;
    }

    
Gets project by name.

Parameters:
name
Returns:
project
Throws:
org.openl.rules.repository.exceptions.RRepositoryException if failed or no project with specified name
    @Deprecated
    public RProject getProject(String namethrows RRepositoryException {
        throw new UnsupportedOperationException();
    }

    
Gets list of projects from the repository.

Returns:
list of projects
Throws:
org.openl.rules.repository.exceptions.RRepositoryException if failed
    @Deprecated
    public List<RProjectgetProjects() throws RRepositoryException {
        throw new UnsupportedOperationException();
    }

    
Gets list of projects from the repository that are marked for deletion.

Returns:
list of projects that are marked for deletion
    @Deprecated
        throw new UnsupportedOperationException();
    }
    public boolean hasDeploymentProject(String namethrows RRepositoryException {
        try {
            return .hasNode(name);
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to check project {0}"ename);
        }
    }
    public boolean hasDeployment(String namethrows RRepositoryException {
        try {
            return .hasNode(name);
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to check project {0}"ename);
        }
    }

    
Checks whether project with given name exists in the repository.

Parameters:
name
Returns:
true if project with such name exists
Throws:
org.openl.rules.repository.exceptions.RRepositoryException
    public boolean hasProject(String namethrows RRepositoryException {
        throw new UnsupportedOperationException();
    }
    public void onEvent(EventIterator eventIterator) {
        boolean hasInterestingEvents = false;
        while (eventIterator.hasNext()) {
            Event event = eventIterator.nextEvent();
            try {
                if (event.getPath().equals( + "/" + )) {
                    hasInterestingEvents = true;
                    break;
                }
            } catch (RepositoryException e) {
                if (.isDebugEnabled()) {
                    .debug("onEvent-1"e);
                }
            }
        }
        if (hasInterestingEvents) {
            Collection<RDeploymentListenerlistenersCopy = new ArrayList<RDeploymentListener>();
            for (RDeploymentListener l : listenersCopy) {
                try {
                    l.projectsAdded();
                } catch (Exception e) {
                    if (.isDebugEnabled()) {
                        .debug("onEvent-2"e);
                    }
                }
            }
        }
    }
    public synchronized boolean removeListener(RDeploymentListener listenerthrows RRepositoryException {
        return .remove(listener);
    }
        try {
            Node node = NodeUtil.createNode(name.true);
            .save();
            node.checkin();
            return new JcrFolderAPI(nodegetTransactionManager(), new ArtefactPathImpl(new String[] { name }));
        } catch (RepositoryException e) {
            throw new  RRepositoryException("",e);
        }
    }
    //FIXME
    private static final Object lock = new Object();
    public void notifyChanges() throws RRepositoryException {
        synchronized () {
            try {
                    .setProperty(., (Stringnull);
                }
                .save();
            } catch (RepositoryException e) {
                throw new RRepositoryException("Failed to notify changes"e);
            }
        }
    }
    
    public FolderAPI createRulesProject(String namethrows RRepositoryException {
        throw new UnsupportedOperationException();
    }
    public FolderAPI getDeploymentProject(String namethrows RRepositoryException {
        Node node;
        try {
            node = .getNode(name);
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to get node"e);
        }
        try {
            return new JcrFolderAPI(nodegetTransactionManager(), new ArtefactPathImpl(new String[] { name }));
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to wrap JCR node"e);
        }
    }
        List<FolderAPIresult = new ArrayList<FolderAPI>();
        try {
            NodeIterator iterator = .getNodes();
            while (iterator.hasNext()) {
                Node node = iterator.nextNode();
                if (node.getPrimaryNodeType().getName().equals(.)) {
                    result.add(new JcrFolderAPI(nodegetTransactionManager(), new ArtefactPathImpl(new String[] { node.getName() })));
                }
            }
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to enumerate deployments"e);
        }
        return result;
    }
    public FolderAPI getRulesProject(String namethrows RRepositoryException {
        throw new UnsupportedOperationException();
    }
    public List<FolderAPIgetRulesProjects() throws RRepositoryException {
        throw new UnsupportedOperationException();
    }
        throw new UnsupportedOperationException();
    }
        List<Stringresult = new ArrayList<String>();
        try {
            NodeIterator iterator = .getNodes();
            while (iterator.hasNext()) {
                Node node = iterator.nextNode();
                if (node.getPrimaryNodeType().getName().equals(.)) {
                    result.add(node.getName());
                }
            }
        } catch (RepositoryException e) {
            throw new RRepositoryException("failed to enumerate deployments"e);
        }
        return result;
    }
    public void addRepositoryListener(RRepositoryListener listener) {
    	throw new UnsupportedOperationException();
    }
    public void removeRepositoryListener(RRepositoryListener listener) {
    	throw new UnsupportedOperationException();
    }
        throw new UnsupportedOperationException();
    }
    @Override
        throws RRepositoryException {
       Map<StringFolderAPIlatestDeployments = new HashMap<StringFolderAPI>();
       Map<StringIntegerversionsList = new HashMap<StringInteger>();
        for (FolderAPI folder : getDeploymentProjects()) {
            String deploymentName = folder.getName();
            Integer versionNum = new Integer(0);
            if(deploymentName.indexOf("#") > -1) {
                String versionStr;
                if(deploymentName.indexOf("#") > deploymentName.lastIndexOf(".")) {
                    versionStr = deploymentName.substring(deploymentName.indexOf("#") + 1,deploymentName.length());
                } else {
                    versionStr = deploymentName.substring(deploymentName.lastIndexOf(".") + 1,deploymentName.length());
                }
                deploymentName = deploymentName.substring(0,deploymentName.indexOf("#"));
                if(!StringUtils.isEmpty(versionStr)) {
                    versionNum = new Integer(versionStr);
                }
            }
            if (versionsList.containsKey(deploymentName)) {
                if (versionNum - versionsList.get(deploymentName) > 0) {
                    versionsList.put(deploymentNameversionNum);
                    latestDeployments.put(deploymentNamefolder);
                }
            } else {
                versionsList.put(deploymentNameversionNum);
                latestDeployments.put(deploymentNamefolder);
            }
        }
        
        return latestDeployments.values();
    }
New to GrepCode? Check out our FAQ X