private CIJobStatus deleteCI(CIJob job, List<String> builds) throws PhrescoException { S_LOGGER.debug("Entering Method CIManagerImpl.deleteCI(CIJob job)"); S_LOGGER.debug("Job name " + job.getName()); cli = getCLI(job); String deleteType = null; List<String> argList = new ArrayList<String>(); S_LOGGER.debug("job name " + job.getName()); S_LOGGER.debug("Builds " + builds); if (CollectionUtils.isEmpty(builds)) { // delete job S_LOGGER.debug("Job deletion started"); S_LOGGER.debug("Command " + FrameworkConstants.CI_JOB_DELETE_COMMAND); deleteType = DELETE_TYPE_JOB; argList.add(FrameworkConstants.CI_JOB_DELETE_COMMAND); argList.add(job.getName()); } else { // delete Build S_LOGGER.debug("Build deletion started"); deleteType = DELETE_TYPE_BUILD; argList.add(FrameworkConstants.CI_BUILD_DELETE_COMMAND); argList.add(job.getName()); StringBuilder result = new StringBuilder(); for (String string : builds) { result.append(string); result.append(","); } String buildNos = result.substring(0, result.length() - 1); argList.add(buildNos); S_LOGGER.debug("Command " + FrameworkConstants.CI_BUILD_DELETE_COMMAND); S_LOGGER.debug("Build numbers " + buildNos); } try { int status = cli.execute(argList); String message = deleteType + " deletion started in jenkins"; if (status == FrameworkConstants.JOB_STATUS_NOTOK) { deleteType = deleteType.substring(0, 1).toLowerCase() + deleteType.substring(1); message = "Error while deleting " + deleteType + " in jenkins"; } S_LOGGER.debug("Delete CI Status " + status); S_LOGGER.debug("Delete CI Message " + message); return new CIJobStatus(status, message); } finally { if (cli != null) { try { cli.close(); } catch (IOException e) { if (debugEnabled) { S_LOGGER.error( "Entered into catch block of CIManagerImpl.deleteCI(CIJob job) " + e.getLocalizedMessage()); } } catch (InterruptedException e) { if (debugEnabled) { S_LOGGER.error( "Entered into catch block of CIManagerImpl.deleteCI(CIJob job) " + e.getLocalizedMessage()); } } } } }
private void deleteJsonJobs(ApplicationInfo appInfo, List<CIJob> selectedJobs) throws PhrescoException { try { if (CollectionUtils.isEmpty(selectedJobs)) { return; } Gson gson = new Gson(); List<CIJob> jobs = getJobs(appInfo); if (CollectionUtils.isEmpty(jobs)) { return; } // all values Iterator<CIJob> iterator = jobs.iterator(); // deletable values for (CIJob selectedInfo : selectedJobs) { while (iterator.hasNext()) { CIJob itrCiJob = iterator.next(); if (itrCiJob.getName().equals(selectedInfo.getName())) { iterator.remove(); break; } } } writeJsonJobs(appInfo, jobs, CI_CREATE_NEW_JOBS); } catch (Exception e) { throw new PhrescoException(e); } }
/** {@inheritDoc} */ public boolean removeAll(Collection<?> c) { if (CollectionUtils.isEmpty(c)) { return false; } writeLock.lock(); try { return super.removeAll(c); } finally { writeLock.unlock(); } }
/** * Convenience method to return a Collection as a delimited (e.g. CSV) String. E.g. useful for * {@code toString()} implementations. * * @param coll the Collection to display * @param delim the delimiter to use (probably a ",") * @param prefix the String to start each element with * @param suffix the String to end each element with * @return the delimited String */ public static String collectionToDelimitedString( Collection<?> coll, String delim, String prefix, String suffix) { if (CollectionUtils.isEmpty(coll)) { return ""; } StringBuilder sb = new StringBuilder(); Iterator<?> it = coll.iterator(); while (it.hasNext()) { sb.append(prefix).append(it.next()).append(suffix); if (it.hasNext()) { sb.append(delim); } } return sb.toString(); }
public CIJob getJob(ApplicationInfo appInfo, String jobName) throws PhrescoException { try { S_LOGGER.debug("Search for jobName => " + jobName); if (StringUtils.isEmpty(jobName)) { return null; } List<CIJob> jobs = getJobs(appInfo); if (CollectionUtils.isEmpty(jobs)) { S_LOGGER.debug("job list is empty!!!!!!!!"); return null; } S_LOGGER.debug("Job list found!!!!!"); for (CIJob job : jobs) { S_LOGGER.debug("job list job Names => " + job.getName()); if (job.getName().equals(jobName)) { return job; } } } catch (Exception e) { throw new PhrescoException(e); } return null; }
/** * Assert that a collection has elements; that is, it must not be {@code null} and must have at * least one element. * * <pre class="code">Assert.notEmpty(collection, "Collection must have elements");</pre> * * @param collection the collection to check * @param message the exception message to use if the assertion fails * @throws AppException if the collection is {@code null} or has no elements */ public static void notEmpty(Collection<?> collection, String message) { if (CollectionUtils.isEmpty(collection)) { throw new AppException(message); } }
/** * Assert that a Map has entries; that is, it must not be <code>null</code> and must have at least * one entry. * * <pre class="code"> * Assert.notEmpty(map, "Map must have entries"); * </pre> * * @param map the map to check * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the map is <code>null</code> or has no entries */ public static void notEmpty(final Map<?, ?> map, final String message) { if (CollectionUtils.isEmpty(map)) { throw new IllegalArgumentException(message); } }
/** * Assert that a collection has elements; that is, it must not be <code>null</code> and must have * at least one element. * * <pre class="code"> * Assert.notEmpty(collection, "Collection must have elements"); * </pre> * * @param collection the collection to check * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the collection is <code>null</code> or has no elements */ public static void notEmpty(final Collection<?> collection, final String message) { if (CollectionUtils.isEmpty(collection)) { throw new IllegalArgumentException(message); } }