Example usage for org.apache.commons.lang ArrayUtils isEmpty

List of usage examples for org.apache.commons.lang ArrayUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils isEmpty.

Prototype

public static boolean isEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is empty or null.

Usage

From source file:com.haulmont.cuba.gui.data.impl.GroupDelegate.java

public void groupBy(Object[] properties, CollectionDatasource.Sortable.SortInfo<MetaPropertyPath>[] sortInfos) {
    if (isGrouping) {
        return;//www.  jav  a 2 s .  com
    }
    isGrouping = true;
    try {
        if (properties != null) {
            CollectionDsHelper.autoRefreshInvalid(datasource, true);

            groupProperties = properties;

            if (!ArrayUtils.isEmpty(groupProperties)) {
                if (datasource.getState() == Datasource.State.VALID) {
                    doGroup();
                } else if (datasource instanceof PropertyDatasource) {
                    datasource.addStateChangeListener(new Datasource.StateChangeListener<T>() {
                        @Override
                        public void stateChanged(Datasource.StateChangeEvent<T> e) {
                            if (e.getState() == Datasource.State.VALID) {
                                doGroup();
                                datasource.removeStateChangeListener(this);
                            }
                        }
                    });
                }
            } else {
                roots = null;
                parents = null;
                children = null;
                groupItems = null;
                itemGroups = null;
            }
        }
    } finally {
        isGrouping = false;

        if (!ArrayUtils.isEmpty(sortInfos)) {
            if (hasGroups()) {
                doGroupSort(sortInfos);
            } else {
                doSort(sortInfos);
            }
        }
    }
}

From source file:com.fibon.maven.confluence.AddPageConfluenceMojo.java

private void uploadPage(RemotePage page) throws MojoFailureException {
    try {//w ww .  j  ava 2 s .  c  o m
        RemotePage created = getClient().getService().storePage(getClient().getToken(), page);
        if (!ArrayUtils.isEmpty(attachments)) {
            new AddAttachmentConfluenceMojo(this, created.getId(), attachments).execute();
        }
        if (outputFile != null) {
            new ExportPageConfluenceMojo(this, created.getId(), outputFile).execute();
        }
    } catch (RemoteException e) {
        throw fail("Unable to upload page", e);
    }
}

From source file:com.mindcognition.mindraider.tools.Checker.java

public static void checkAndFixRepository() {
    logger.debug("Repository integrity check..."); // {{debug}}
    // fields/*  www . jav  a 2 s.co  m*/
    HashSet<ResourceDescriptor> allOutlines = new HashSet<ResourceDescriptor>();
    OutlineCustodian outlineCustodian = MindRaider.outlineCustodian;
    int fixes = 0;
    int totalConcepts = 0;

    // labels (folders) RDF
    Model labelsRdfModel = MindRaider.labelCustodian.getRdfModel(); // folders.rdf.xml

    ResourceDescriptor[] labelDescriptors = MindRaider.labelCustodian.getLabelDescriptors();

    if (!ArrayUtils.isEmpty(labelDescriptors)) {
        for (ResourceDescriptor labelDescriptor : labelDescriptors) {
            String labelUri = labelDescriptor.getUri();

            // check whether [label]/folder.xml exists (eventually re-create it)
            StatusBar.show("Checking label XML resource: " + labelUri);
            Resource labelXmlResource = MindRaider.labelCustodian.get(labelUri);
            if (labelXmlResource == null) {
                try {
                    StatusBar.show("Fixing label XML resource: " + labelUri);
                    // create directory
                    String labelDirectory = MindRaider.labelCustodian.createLabelDirectory(labelUri);
                    // resource
                    Resource resource = MindRaider.labelCustodian
                            .createXmlResourceForLabel(labelDescriptor.getLabel(), labelUri);
                    MindRaider.labelCustodian.addOutlinesGroupToLabelXmlResource(resource);
                    resource.toXmlFile(MindRaider.labelCustodian.getLabelXmlResourceFileName(labelDirectory));

                    // label resource doesn't exist => must be re-created from RDF
                    ResourceDescriptor[] outlineDescriptors = MindRaider.labelCustodian
                            .getOutlineDescriptors(labelUri);
                    if (outlineDescriptors != null && outlineDescriptors.length > 0) {
                        for (int i = 0; i < outlineDescriptors.length; i++) {
                            MindRaider.labelCustodian.addOutlineToLabelXmlResourceAndSave(labelUri,
                                    outlineDescriptors[i].getUri());
                            System.out.println("Fixing label XML resource: " + labelUri + " -> "
                                    + outlineDescriptors[i].getUri());
                            ++fixes;
                        }
                    }
                } catch (Exception ee) {
                    logger.debug("Unable to fix label: " + labelDescriptor.getUri(), ee); // {{debug}}
                }
            }

            // folder.rdf.xml
            ResourceDescriptor[] outlineDescriptors = MindRaider.labelCustodian.getOutlineDescriptors(labelUri);
            if (outlineDescriptors != null) {
                for (ResourceDescriptor outlineDescriptor : outlineDescriptors) {
                    if (!allOutlines.contains(outlineDescriptor)) {
                        allOutlines.add(outlineDescriptor);
                        StatusBar.show("Checking outline: " + outlineDescriptor.getLabel() + " ("
                                + outlineDescriptor.getUri() + ")");
                        logger.debug("  Outline: '" + outlineDescriptor.getLabel() + "', "
                                + outlineDescriptor.getUri()); // {{debug}}

                        Model outlineRdfModel;
                        OutlineResource outlineResource;

                        Resource outlineXmlResource;
                        String outlineModelFilename;
                        String outlineResourceFilename;

                        try {
                            // outline's RDF (notebook.rdf.xml)
                            outlineModelFilename = outlineCustodian.getModelFilenameByDirectory(
                                    outlineCustodian.getOutlineDirectory(outlineDescriptor.getUri()));
                            logger.debug("    RDF: " + outlineModelFilename);
                            outlineRdfModel = RdfModel.loadModel(outlineModelFilename, false);

                            // detect whether it is active outline
                            if (MindRaider.outlineCustodian.getActiveOutlineResource() != null
                                    && MindRaider.outlineCustodian.getActiveOutlineResource().getUri()
                                            .equals(outlineDescriptor.getUri())) {
                                //JOptionPane.showConfirmDialog(MindRaider.mainJFrame, "Fixing active outline: "+outlineDescriptor.getUri());
                                outlineRdfModel = MindRaider.spidersGraph.getRdfModel().getModel();
                            }

                            if (outlineRdfModel == null) {
                                // RDF model doesn't exist - such outline can not be restored, just delete it
                                final String fixMessage = "Fix: removing broken outline '"
                                        + outlineDescriptor.getLabel() + "'";
                                StatusBar.show(fixMessage);
                                System.out.println(fixMessage);

                                // check that outline is NOT BROKEN - otherwise standard functions will not
                                // be able to discard and delete it
                                com.hp.hpl.jena.rdf.model.Resource orphan = labelsRdfModel
                                        .getResource(outlineDescriptor.getUri());
                                if (orphan != null) {
                                    logger.debug("  Orphan outline found: " + outlineDescriptor.getUri()); // {{debug}}
                                    if (RdfModel.getLabel(labelsRdfModel, orphan) == null) {
                                        logger.debug("    ... having no label"); // {{debug}}
                                        if (RdfModel.getHref(labelsRdfModel, orphan) == null) {
                                            logger.debug("    ... having no href"); // {{debug}}
                                            // if it has no HREF, then fix it -> standard functions will delete that
                                            String relativePath = MindRaider.profile
                                                    .getRelativePath(outlineCustodian
                                                            .getOutlineDirectory(outlineDescriptor.getUri()));
                                            RdfModel.setHref(orphan,
                                                    relativePath + OutlineCustodian.FILENAME_XML_RESOURCE);
                                        }
                                    }
                                }

                                MindRaider.labelCustodian.discardOutline(outlineDescriptor.getUri());
                                MindRaider.labelCustodian.deleteOutline(outlineDescriptor.getUri());
                                ++fixes;

                                continue;
                            }

                            // outline's XML (notebook.xml)
                            outlineResourceFilename = outlineCustodian.getResourceFilenameByDirectory(
                                    outlineCustodian.getOutlineDirectory(outlineDescriptor.getUri()));
                            logger.debug("    XML: " + outlineResourceFilename);
                            outlineXmlResource = new Resource(outlineResourceFilename);
                            outlineResource = new OutlineResource(outlineXmlResource);
                        } catch (Exception e) {
                            logger.debug("Unable to load outline" + outlineDescriptor.getUri(), e);
                            // TODO fix it
                            continue;
                        }
                        //logger.debug("    Loaded: "+outlineRdfModel+" / "+outlineXmlResource); // {{debug}}

                        // FIX outline label: on rename changed only in folder's RDF, not xml name (and notebook's XML)
                        // FIX rename: notebook name is changed on rename ONLY in the labels (folders) RDF model,
                        //             in here it is propagated to notebook's XML and (notebook.xml) and RDF (notebook.rdf.xml) 
                        String outlineLabel = MindRaider.labelCustodian
                                .getOutlineDescriptor(outlineDescriptor.getUri()).getLabel();
                        String outlineComment = "'" + outlineLabel + "' outline.";
                        if (outlineLabel != null && outlineLabel.length() > 0) {
                            if (!outlineLabel.equals(outlineResource.getLabel())) {
                                fixes++;
                                StatusBar.show("Fixing title and description: " + outlineDescriptor.getUri());
                                System.out.println("    Fix: inconsistent outline's title & description ("
                                        + outlineDescriptor.getUri() + ")"); // {{debug}}
                                logger.debug("      Label's RDF  : " + outlineLabel); // {{debug}}                                    
                                logger.debug("      Outline's XML: " + outlineResource.getLabel()); // {{debug}}                                    
                                if (outlineResource.getLabelProperty() != null) {
                                    outlineResource.getLabelProperty().setLabelContent(outlineLabel);
                                }
                                if (outlineResource.getAnnotationProperty() != null) {
                                    outlineResource.getAnnotationProperty().setAnnotation(outlineComment);
                                }
                                try {
                                    outlineResource.save();
                                } catch (Exception e) {
                                    logger.debug("Unable to save outline XML resource", e); // {{debug}}
                                }
                            }
                        }
                        com.hp.hpl.jena.rdf.model.Resource rdfResource = outlineRdfModel
                                .getResource(outlineDescriptor.getUri());
                        if (rdfResource != null) {
                            rdfResource.removeAll(RDFS.label);
                            rdfResource.addProperty(RDFS.label, outlineLabel);
                            rdfResource.removeAll(RDFS.comment);
                            rdfResource.addProperty(RDFS.comment, outlineComment);
                            RdfModel.saveModel(outlineRdfModel, outlineModelFilename);
                        }

                        // iterate outline's concepts
                        final SimpleSelector simpleSelector = new SimpleSelector(null, RDF.type,
                                outlineRdfModel.createResource(MindRaiderConstants.MR_OWL_CLASS_CONCEPT));
                        StmtIterator conceptsIterator = outlineRdfModel.listStatements(simpleSelector);
                        while (conceptsIterator.hasNext()) {
                            ++totalConcepts;
                            Statement statement = (Statement) conceptsIterator.next();

                            final com.hp.hpl.jena.rdf.model.Resource conceptRdfResource = statement
                                    .getSubject();
                            //logger.debug("  Concept: " +totalConcepts+" "+conceptRdfResource.getURI());

                            // TODO check whether the concept is in notebook.xml

                            // load note resource [concept name].xml
                            try {
                                ConceptResource noteResource = MindRaider.noteCustodian
                                        .get(outlineDescriptor.getUri(), conceptRdfResource.getURI());

                                // TODO check and fix note's attachments: if attachment is in the resource and not in RDF, add it to RDF
                                logger.debug("Attachments:");
                                AttachmentProperty[] attachments = noteResource.getAttachments();
                                if (attachments != null && attachments.length > 0) {
                                    for (AttachmentProperty attachmentProperty : attachments) {
                                        logger.debug("  " + attachmentProperty.getUrl());

                                        StmtIterator listStatements = outlineRdfModel
                                                .listStatements(conceptRdfResource,
                                                        outlineRdfModel.getProperty(
                                                                MindRaiderConstants.MR_RDF_NS, "attachment"),
                                                        attachmentProperty.getUrl());
                                        if (!listStatements.hasNext()) {
                                            //JOptionPane.showConfirmDialog(MindRaider.mainJFrame, "Missing attach in RDF: "+attachmentProperty.getUrl());
                                            conceptRdfResource.addProperty(
                                                    outlineRdfModel.getProperty(
                                                            MindRaiderConstants.MR_RDF_NS + "attachment"),
                                                    attachmentProperty.getUrl());
                                            RdfModel.saveModel(outlineRdfModel, outlineModelFilename);
                                            ++fixes;
                                        }
                                    }
                                }

                            } catch (Exception e) {
                                // there is a problem (file doesn't exist, it is empty file, ...)
                                // fix: build *.xml resource from RDF and write it back

                                // rdf contains: label/timestamp/comment/?attachments ignored for now
                                String label = RdfModel.getLabel(outlineRdfModel, conceptRdfResource);
                                String comment = RdfModel.getComment(outlineRdfModel, conceptRdfResource);
                                long timestamp = RdfModel.getTimestamp(outlineRdfModel, conceptRdfResource);

                                try {
                                    ConceptResource conceptResource = new ConceptResource(
                                            new Resource(MindRaider.profile.getProfileName(), timestamp, 1,
                                                    System.currentTimeMillis(), conceptRdfResource.getURI()));
                                    conceptResource.resource.getMetadata()
                                            .setMindRaiderVersion(MindRaider.getVersion());
                                    conceptResource.resource.getMetadata()
                                            .setType(MindRaiderConstants.MR_OWL_CLASS_CONCEPT);
                                    conceptResource.resource.getData().addProperty(new LabelProperty(label));
                                    conceptResource.resource.getData()
                                            .addProperty(new AnnotationProperty(comment));
                                    conceptResource.resource.getData()
                                            .addProperty(new AnnotationContentTypeProperty(
                                                    MindRaiderConstants.MR_OWL_CONTENT_TYPE_PLAIN_TEXT));
                                    conceptResource.resource.getData().addProperty(
                                            new NotebookProperty(new URI(outlineDescriptor.getUri())));

                                    conceptResource.resource
                                            .toXmlFile(MindRaider.noteCustodian.getConceptResourceFilename(
                                                    outlineDescriptor.getUri(), conceptRdfResource.getURI()));
                                } catch (Exception exception) {
                                    logger.error("Unable to ressurect concept from RDF - deleting "
                                            + conceptRdfResource.getURI(), e);

                                    // TODO purge concept from the filesystem (a robust implementation that expects 
                                    // that [concept].xml is not there/is locked

                                    // TODO do purge
                                }
                            }
                        }

                        // TODO FIX: remove concepts from notebook.xml.rdf, that do not exist in notebook.xml OR rather create notebook.xml from what's in RDF
                        // TODO FIX: concepts in RDF vs. notebook.xml vs. on the filesystem 

                        // TODO run discarded :-)
                        MindRaider.outlineCustodian.getDiscardedConceptDescriptors(outlineDescriptor.getUri());

                    }
                }
            }
        }
    }

    // TODO rebuild search index (after low level changes, FTS index must be updated)

    // clean memory
    Runtime.getRuntime().runFinalization();
    Runtime.getRuntime().gc();

    logger.debug("Total outlines: " + allOutlines.size()); // {{debug}}
    logger.debug("Fixed problems: " + fixes); // {{debug}}
    StatusBar.show("Check & fix results: total outlines " + allOutlines.size() + ", total concepts "
            + totalConcepts + ", fixed problems " + fixes);
}

From source file:com.sccl.attech.modules.sms.service.SmsService.java

/**
 * Send sms. ??//from w  w  w .j a  va  2s  . com
 * 
 * @param mobiles the ??,,
 * @return the result info
 */
public ResultInfo sendSms(String mobiles, String content) {
    if (logger.isDebugEnabled()) {
        logger.debug("sendSms(String=" + mobiles + ", String=" + content + ") - ");
    }

    SmsRequest request = initRequest(mobiles, content);
    ResultInfo resultInfo = new ResultInfo();
    resultInfo.setResult(SmsReceiver.SMS_STATUS_SUCCESS);
    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
    Client client = dcf.createClient(Global.getConfig(SMS_KEY_ADDR));
    try {
        if (logger.isInfoEnabled()) {
            logger.info("?" + Global.getConfig(SMS_KEY_ADDR) + ":"
                    + Global.getConfig(SMS_KEY_METHOD) + ",??" + request);
        }
        String requestXml = JaxbUtil.convertToXml(request);
        System.out.println(requestXml);
        Object[] result = client.invoke(Global.getConfig(SMS_KEY_METHOD), requestXml);
        if (ArrayUtils.isEmpty(result) || null == result[0]) {
            resultInfo.setResult("0");
            resultInfo.setMessage("?");

            if (logger.isDebugEnabled()) {
                logger.debug("sendSms(String=" + mobiles + ", String=" + content + ") - ? - ="
                        + resultInfo);
            }
            return resultInfo;
        }
        if (logger.isInfoEnabled()) {
            logger.info("?" + Global.getConfig(SMS_KEY_ADDR) + ":"
                    + Global.getConfig(SMS_KEY_METHOD) + "," + result[0]);
        }
        SmsResponse response = JaxbUtil.converyToJavaBean((String) result[0], SmsResponse.class);
        resultInfo = response.getResultInfo();
    } catch (Exception e) {
        logger.error("sendSms(String=" + mobiles + ", String=" + content + ") - ", e);

        e.printStackTrace();
        resultInfo.setResult(SmsReceiver.SMS_STATUS_FAILE);
        resultInfo.setMessage(e.getMessage());
    }

    if (logger.isDebugEnabled()) {
        logger.debug(
                "sendSms(String=" + mobiles + ", String=" + content + ") - ? - =" + resultInfo);
    }
    return resultInfo;
}

From source file:fr.mby.saml2.sp.impl.web.Saml20RequestWrapper.java

/**
 * Extended parametters whose includes initial CAS request parameters. {@inheritDoc}
 *///from   ww w .  j  a  v a 2 s.  c om
@Override
public String getParameter(final String paramName) {
    String result = null;

    final String[] values = this.getParameterValues(paramName);
    if (!ArrayUtils.isEmpty(values)) {
        result = values[0];
    }

    return result;
}

From source file:de.codesourcery.eve.skills.ui.utils.ParallelUITasksRunner.java

public static boolean submitParallelTasks(final ApplicationThreadManager threadManager, final UITask parent,
        UITask... children) {//w  ww.jav  a2s  . co m
    final AtomicInteger childSuccesses = new AtomicInteger(0);
    final AtomicInteger childFailures = new AtomicInteger(0);

    if (parent == null) {
        throw new IllegalArgumentException("parent task cannot be NULL");
    }

    if (ArrayUtils.isEmpty(children)) {
        throw new IllegalArgumentException("Need to provide at least one child task");
    }
    final CyclicBarrier startBarrier = new CyclicBarrier(children.length + 1) {
        @Override
        public void reset() {
            System.out.println("========== resetting start barrier =========== ");
            super.reset();
        }
    };

    final CountDownLatch childrenTerminated = new CountDownLatch(children.length);

    int submittedChildren = 0;
    for (final UITask child : children) {

        final UITask wrapped = new UITask() {

            @Override
            public void successHook() throws Exception {
                boolean success = false;
                try {
                    child.successHook();
                    success = true;
                } finally {
                    if (success) {
                        childSuccesses.incrementAndGet();
                    } else {
                        childFailures.incrementAndGet();
                    }
                    childrenTerminated.countDown();
                }
            }

            @Override
            public void beforeExecution() {
                child.beforeExecution();
                // note: when this method throws an exception , #failure() is invoked
            }

            @Override
            public void setEnabledHook(boolean yesNo) {
                child.setEnabledHook(yesNo);

            }

            @Override
            public void failureHook(Throwable t) throws Exception {
                try {
                    child.failureHook(t);
                } finally {
                    childFailures.incrementAndGet();
                    childrenTerminated.countDown();
                }
            }

            @Override
            public void cancellationHook() {
                try {
                    child.cancellationHook();
                } finally {
                    childFailures.incrementAndGet();
                    childrenTerminated.countDown();
                }
            }

            @Override
            public String getId() {
                return child.getId();
            }

            @Override
            public void run() throws Exception {
                try {
                    if (log.isTraceEnabled()) {
                        log.trace("run(): Child task " + getId() + " is now waiting.");
                    }
                    startBarrier.await(); // will BrokenBarrierException if any of the child tasks could not be started,
                } catch (InterruptedException e) {
                    log.error("run(): Child task " + getId() + " was interrupted");
                    Thread.currentThread().interrupt();
                } catch (BrokenBarrierException e) {
                    log.error("run(): Child task" + getId() + " aborted, barrier broken.");
                    throw new RuntimeException(
                            "Child task not started because another child task failed submitTask()");
                }

                if (log.isTraceEnabled()) {
                    log.trace("run(): Child task " + getId() + " is now running.");
                }
                child.run();
            }
        };

        if (null == threadManager.submitTask(wrapped, false)) {
            log.error("submitParallelTasks(): Failed to submit child " + child);

            // note: I wait for (submittedChildren-childFailures) because some 
            // child task may have already failed before reaching their run() method
            while (startBarrier.getNumberWaiting() != (submittedChildren - childFailures.get())) {
                log.info("submitParallelTasks(): Waiting for all child tasks to reach barrier ( "
                        + startBarrier.getNumberWaiting() + " waiting)");
                try {
                    java.lang.Thread.sleep(500);
                } catch (Exception e) {
                }
                ;
            }

            startBarrier.reset(); // will cause all child threads waiting on this barrier to terminate
            return false;
        }
        submittedChildren++;
    }

    /*
     * All children are submitted and waiting at the barrier.
     */
    final boolean parentSubmitted = null != threadManager.submitTask("Control thread of " + parent.getId(),
            new Runnable() {

                @Override
                public void run() {
                    try {

                        while (true) {
                            try {
                                log.debug("run(): Parent task " + parent.getId()
                                        + " is waiting for it's children to start...");
                                startBarrier.await(5, TimeUnit.SECONDS);
                                break;
                            } catch (TimeoutException e) {
                                if (childFailures.get() != 0) {
                                    runFailureHookOnEDT(parent,
                                            childFailures.get() + " child tasks of parent task "
                                                    + parent.getId() + " failed to start.");
                                    return;
                                }
                            }
                        }
                    } catch (InterruptedException e) {
                        runFailureHookOnEDT(parent, "Parent task " + parent.getId()
                                + " was interrupted while waiting" + " for it's children to start.");
                        startBarrier.reset(); // let children fail.
                        Thread.currentThread().interrupt();
                        return;
                    } catch (BrokenBarrierException e) {
                        runFailureHookOnEDT(parent,
                                "Parent task " + parent.getId() + " failed to wait for it's children");
                        throw new RuntimeException("Internal error - task " + parent.getId()
                                + " failed to wait for it's children?");
                    }

                    log.debug("run(): Task " + parent.getId() + " is waiting for it's children to finish");
                    try {
                        childrenTerminated.await();
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        runFailureHookOnEDT(parent, "Parent task " + parent.getId()
                                + " was interrupted while waiting for it's children");
                        return;
                    }

                    log.info("run(): All children of parent task " + parent.getId()
                            + " have finished ( success: " + childSuccesses.get() + " / failure: "
                            + childFailures.get() + ")");

                    if (childFailures.get() > 0) {
                        runFailureHookOnEDT(parent, childFailures.get() + " child tasks of parent "
                                + parent.getId() + " have FAILED.");
                        return;
                    }

                    if (null == threadManager.submitTask(parent, false)) {
                        runFailureHookOnEDT(parent, "Failed to submit parent task " + parent.getId());
                        return;
                    }

                }
            }, false);

    if (!parentSubmitted) {
        log.debug("submitParallelTasks(): Failed to submit parent task " + parent.getId()
                + " , terminating child tasks.");
        startBarrier.reset(); // aborts all child tasks with a BrokenBarrierException
    }

    return parentSubmitted;
}

From source file:hudson.plugins.clearcase.action.SnapshotCheckoutAction.java

public boolean checkout(Launcher launcher, FilePath workspace, String viewTag)
        throws IOException, InterruptedException {
    boolean viewCreated = cleanAndCreateViewIfNeeded(workspace, viewTag, viewPath, null);

    // At this stage, we have a valid view and a valid path
    boolean needSetCs = true;
    AbstractCheckoutAction.LoadRulesDelta loadRulesDelta = null;
    if (!viewCreated) {
        ConfigSpec viewConfigSpec = new ConfigSpec(cleartool.catcs(viewTag), launcher.isUnix());
        loadRulesDelta = getLoadRulesDelta(viewConfigSpec.getLoadRules(), launcher);
        needSetCs = !configSpec.stripLoadRules().equals(viewConfigSpec.stripLoadRules())
                || !ArrayUtils.isEmpty(loadRulesDelta.getRemoved());
    }//  w  ww. j a  v a2 s  . c  o  m

    if (needSetCs) {
        try {
            cleartool.setcs(viewPath, SetcsOption.CONFIGSPEC, configSpec.setLoadRules(loadRules).getRaw());
        } catch (IOException e) {
            launcher.getListener().fatalError(e.toString());
            return false;
        }
    } else {
        String[] addedLoadRules = loadRulesDelta.getAdded();
        if (!ArrayUtils.isEmpty(addedLoadRules)) {
            // Config spec haven't changed, but there are new load rules
            try {
                cleartool.update(viewPath, addedLoadRules);
            } catch (IOException e) {
                launcher.getListener().fatalError(e.toString());
                return false;
            }
        }
    }
    // Perform a full update of the view. to reevaluate config spec
    if (!viewCreated) {
        try {
            cleartool.setcs(viewPath, SetcsOption.CURRENT, null);
        } catch (IOException e) {
            launcher.getListener().fatalError(e.toString());
            return false;
        }
    }
    return true;
}

From source file:hudson.plugins.clearcase.action.UcmSnapshotCheckoutAction.java

@Override
public boolean checkout(Launcher launcher, FilePath workspace, String viewTag)
        throws IOException, InterruptedException {
    boolean viewCreated = cleanAndCreateViewIfNeeded(workspace, viewTag, viewPath, streamSelector);
    // At this stage, we have a valid view and a valid path
    if (viewCreated) {
        // If the view is brand new, we just have to add the load rules
        try {// www.  j a v  a  2s  . c  om
            cleartool.update(viewPath, loadRules);
        } catch (IOException e) {
            launcher.getListener().fatalError(e.toString());
            return false;
        }
    } else {
        ConfigSpec viewConfigSpec = new ConfigSpec(cleartool.catcs(viewTag), launcher.isUnix());
        AbstractCheckoutAction.LoadRulesDelta loadRulesDelta = getLoadRulesDelta(viewConfigSpec.getLoadRules(),
                launcher);
        if (!ArrayUtils.isEmpty(loadRulesDelta.getRemoved())) {
            try {
                cleartool.setcs(viewPath, SetcsOption.CONFIGSPEC,
                        viewConfigSpec.setLoadRules(loadRules).getRaw());
            } catch (IOException e) {
                launcher.getListener().fatalError(e.toString());
                return false;
            }
        } else {
            String[] addedLoadRules = loadRulesDelta.getAdded();
            if (!ArrayUtils.isEmpty(addedLoadRules)) {
                // Config spec haven't changed, but there are new load rules
                try {
                    cleartool.update(viewPath, addedLoadRules);
                } catch (IOException e) {
                    launcher.getListener().fatalError(e.toString());
                    return false;
                }
            }
        }

        // Perform a full update of the view to get changes due to rebase for instance.
        try {
            cleartool.update(viewPath, null);
        } catch (IOException e) {
            launcher.getListener().fatalError(e.toString());
            return false;
        }
    }
    return true;
}

From source file:net.jforum.repository.PostReportDao.java

private Query createGetAllQuery(PostReportStatus status, int... forumIds) {
    String query = "select new PostReport(report.id, post.id, post.subject, post.topic.id, report.date, "
            + "report.description, reportUser.username, reportUser.id, postUser.username, postUser.id, report.status)"
            + " from PostReport report " + " join report.user reportUser " + " join report.post post"
            + " join post.user postUser " + " where report.status = :status";

    if (!ArrayUtils.isEmpty(forumIds)) {
        query += " and post.forum.id in (:forumIds)";
    }/*from   ww  w .j  a  v  a2 s . com*/

    if (!ArrayUtils.isEmpty(forumIds)) {
        return session.createQuery(query).setParameter("status", status).setParameterList("forumIds",
                this.primitiveToWrapper(forumIds));
    } else {
        return session.createQuery(query).setParameter("status", status);
    }
}

From source file:com.nec.harvest.service.impl.ActualViewServiceImpl.java

/** {@inheritDoc}*/
@Override/*ww  w. j a v  a2  s.c o m*/
public List<VJiseki> findByOrgCodeAndMonthies(String orgCode, String... monthlies) throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException("Organization must not be null or empty");
    }
    if (ArrayUtils.isEmpty(monthlies)) {
        throw new IllegalArgumentException("The monthlies must not be null");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<VJiseki> jisekis = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        Query query = repository.getSQLQuery(session,
                "SELECT  UriSkKG as uriSkKG, KtSkKG as ktSkKG, IdoSkKGU as idoSkKGU, IdoSkKGH as idoSkKGH, UriKrKG as uriKrKG,"
                        + " KtKrKG as ktKrKG, KnSrKG as knSrKG, KtSrKG as ktSrKG, KgcSrKG as kgcSrKG, IdoSrKGU as idoSrKGU, IdoSrKGH as idoSrKGH, KtJkKG as ktJkKG, JkJkKG as jkJkKG, KgcJkKG as kgcJkKG, IdoJkKGU as idoJkKGU, IdoJkKGH as idoJkKGH, HelpJkKGU as helpJkKGU, "
                        + " HelpJkKGH as helpJkKGH, KtKhKG as ktKhKG, KnKhKG as knKhKG, KgcKhKG as kgcKhKG, IdoKhKGU as idoKhKGU, IdoKhKGH as idoKhKGH, UriKhKG as uriKhKG FROM V_JISEKI WHERE StrCode = :strCode AND Getsudo in (:monthlies)");
        query.setParameter("strCode", orgCode);
        query.setParameterList("monthlies", monthlies);
        query.setResultTransformer(Transformers.aliasToBean(VJiseki.class));

        jisekis = repository.findByQuery(query);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(jisekis)) {
            throw new ObjectNotFoundException("There is no actual view object");
        }
    } catch (SQLGrammarException | GenericJDBCException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException(
                "An exception occured while getting VJiseki data for the organization " + orgCode, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return jisekis;
}