List of usage examples for org.apache.commons.lang ArrayUtils isNotEmpty
public static boolean isNotEmpty(boolean[] array)
Checks if an array of primitive booleans is not empty or not null
.
From source file:org.onehippo.forge.content.exim.repository.jaxrs.ContentEximImportService.java
private int cleanSingleDocbaseFieldValues(Logger procLogger, ProcessStatus processStatus, Session session, ExecutionParams params, String docbasePropName, Result result, int batchCount) throws Exception { Set<String> nodePaths = getQueriedNodePaths(session, "//element(*)[jcr:like(@" + docbasePropName + ",'/content/%')]", Query.XPATH); session.refresh(false);/*from w w w . ja va 2 s.c om*/ for (String nodePath : nodePaths) { try { if (!session.nodeExists(nodePath)) { continue; } Node node = session.getNode(nodePath); if (!node.hasProperty(docbasePropName)) { continue; } Property docbaseProp = node.getProperty(docbasePropName); if (docbaseProp.isMultiple()) { String[] docbasePaths = JcrUtils.getMultipleStringProperty(node, docbasePropName, null); if (ArrayUtils.isNotEmpty(docbasePaths)) { boolean updated = false; for (int i = 0; i < docbasePaths.length; i++) { String docbasePath = docbasePaths[i]; if (StringUtils.startsWith(docbasePath, "/") && session.nodeExists(docbasePath)) { String docbase = session.getNode(docbasePath).getIdentifier(); docbasePaths[i] = docbase; updated = true; } } if (updated) { JcrUtils.ensureIsCheckedOut(node); node.setProperty(docbasePropName, docbasePaths); } } } else { String docbasePath = JcrUtils.getStringProperty(node, docbasePropName, null); if (StringUtils.startsWith(docbasePath, "/") && session.nodeExists(docbasePath)) { JcrUtils.ensureIsCheckedOut(node); String docbase = session.getNode(docbasePath).getIdentifier(); node.setProperty(docbasePropName, docbase); } } } catch (Exception e) { String message = "Failed to clean mirror docbase value at " + nodePath + "/@" + docbasePropName + ". " + e; result.addError(message); procLogger.error("Failed to clean mirror docbase value at {}/@{}.", nodePath, docbasePropName, e); } finally { ++batchCount; if (batchCount % params.getBatchSize() == 0) { session.save(); session.refresh(false); if (params.getThrottle() > 0) { Thread.sleep(params.getThrottle()); } } } } session.save(); session.refresh(false); return batchCount; }
From source file:org.opencastproject.publication.youtube.YouTubeAPIVersion3ServiceImpl.java
@Override public Video addVideoToMyChannel(final VideoUpload videoUpload) throws IOException { final Video videoObjectDefiningMetadata = new Video(); final VideoStatus status = new VideoStatus(); status.setPrivacyStatus(videoUpload.getPrivacyStatus()); videoObjectDefiningMetadata.setStatus(status); // Metadata lives in VideoSnippet final VideoSnippet snippet = new VideoSnippet(); snippet.setTitle(videoUpload.getTitle()); snippet.setDescription(videoUpload.getDescription()); final String[] tags = videoUpload.getTags(); if (ArrayUtils.isNotEmpty(tags)) { snippet.setTags(Collections.list(tags)); }//from w w w . jav a2s .c om // Attach metadata to video object. videoObjectDefiningMetadata.setSnippet(snippet); final File videoFile = videoUpload.getVideoFile(); final BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(videoFile)); final InputStreamContent mediaContent = new InputStreamContent("video/*", inputStream); mediaContent.setLength(videoFile.length()); final YouTube.Videos.Insert videoInsert = youTube.videos().insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent); final MediaHttpUploader uploader = videoInsert.getMediaHttpUploader(); uploader.setDirectUploadEnabled(false); uploader.setProgressListener(videoUpload.getProgressListener()); return execute(videoInsert); }
From source file:org.openinfinity.cloud.service.healthmonitoring.HealthMonitoringServiceImpl.java
@Override public HealthStatusResponse getHealthStatus(String sourceName, String sourceType, String metricType, String[] metricNames, Date startTime, Date endTime) { HealthStatusResponse response = null; if (StringUtils.isNotBlank(sourceName) && StringUtils.isNotBlank(metricType) && ArrayUtils.isNotEmpty(metricNames)) { String hostName = ""; if (groupMachineMap.get(sourceName) != null) { hostName = groupMachineMap.get(sourceName); } else {/*from w ww.j av a 2 s .co m*/ hostName = hostnameIpMap.get(sourceName); } String url = getRequestBuilder(hostName).buildHealthStatusRequest( new Request(sourceName, sourceType, metricType, metricNames, startTime, endTime, 100L)); String responseStr = HttpHelper.executeHttpRequest(client, url); response = toObject(responseStr, HealthStatusResponse.class); LOG.debug("Request for machine " + url); } else { response = new HealthStatusResponse(); response.setResponseStatus(AbstractResponse.STATUS_PARAM_FAIL); } return response; }
From source file:org.openinfinity.cloud.service.healthmonitoring.HealthMonitoringServiceImpl.java
@Override public HealthStatusResponse getClusterHealthStatus(Machine machine, String metricType, String[] metricNames, Date date) {/*from w w w. ja va2s .com*/ HealthStatusResponse response = null; if (StringUtils.isNotBlank(metricType) && ArrayUtils.isNotEmpty(metricNames) && machine != null) { String groupName = HM_GROUPNAME_PREFIX + machine.getClusterId(); String url = getRequestBuilder(machine.getDnsName()).buildHealthStatusRequest( new Request(groupName, Request.SOURCE_GROUP, metricType, metricNames, date, date, 1L)); String responseStr = HttpHelper.executeHttpRequest(client, url); // FIXME: handling in case that response is of type error response = toObject(responseStr, HealthStatusResponse.class); LOG.debug("Request for machine " + url); } else { response = new HealthStatusResponse(); response.setResponseStatus(AbstractResponse.STATUS_PARAM_FAIL); } return response; }
From source file:org.openinfinity.cloud.service.healthmonitoring.HealthMonitoringServiceImpl.java
@Override public HealthStatusResponse getLatestAvailabaleClusterHealthStatus(Machine machine, String metricType, String[] metricNames, Date date) { HealthStatusResponse response = null; // Validate input parameters if (StringUtils.isNotBlank(metricType) && ArrayUtils.isNotEmpty(metricNames) && machine != null && machine.getClusterId() > 0) { // Form request String groupName = HM_GROUPNAME_PREFIX + machine.getClusterId(); String url = getRequestBuilder(machine.getDnsName()).buildLastHealthStatusRequest( new Request(groupName, Request.SOURCE_GROUP, metricType, metricNames, date, date, RRA_STEP)); LOG.debug("Request for machine " + url); // Execute request String responseStr = HttpHelper.executeHttpRequest(client, url); // Handle response if (responseStr == null) { response = new HealthStatusResponse(); response.setResponseStatus(AbstractResponse.STATUS_NODE_FAIL); } else {//from www.j a va 2 s. co m response = toObject(responseStr, HealthStatusResponse.class); response.setResponseStatus(AbstractResponse.STATUS_OK); } } else { response = new HealthStatusResponse(); response.setResponseStatus(AbstractResponse.STATUS_PARAM_FAIL); } return response; }
From source file:org.opentestsystem.authoring.testspecbank.client.TestSpecBankClient.java
@Override public TestSpecificationSearchResponse getTestSpecificationByTenantSet(final Set<String> tenantIds, Map<String, String[]> parameterMap) { TestSpecificationSearchResponse response; if (parameterMap == null) { parameterMap = Maps.newHashMap(); }/* ww w. j a va 2 s . c om*/ final String[] tenants = tenantIds.toArray(new String[0]); if (ArrayUtils.isNotEmpty(tenants)) { parameterMap.put("tenantSet", tenants); } try { return this.tsbRestTemplate.getForObject(this.baseUri + buildTestSpecURL(parameterMap), TestSpecificationSearchResponse.class, convertStringArray(parameterMap)); } catch (final RestClientException e) { response = new TestSpecificationSearchResponse(); LOGGER.error("Error searching for test specifications", e); } return response; }
From source file:org.ovirt.engine.api.common.util.DetailHelper.java
/** * Determines what details to include or exclude from the {@code detail} parameter of the {@code Accept} header and * from the {@code detail} matrix or query parameters. * * @param headers the object that gives access to the HTTP headers of the request, may be {@code null} in which case * it will be completely ignored// w w w .ja v a2 s .c om * @param uri the object that gives access to the URI information, may be {@code null} in which case it will be * completely ignored * @return the set containing the extracted information, may be empty, but never {@code null} */ public static Set<String> getDetails(HttpHeaders headers, UriInfo uri) { // We will collect the detail specifications obtained from different places into this list, for later // processing: List<String> allSpecs = new ArrayList<>(0); // Try to extract the specification of what to include/exclude from the accept header: if (headers != null) { List<String> headerValues = headers.getRequestHeader(ACCEPT); if (CollectionUtils.isNotEmpty(headerValues)) { for (String headerValue : headerValues) { HeaderElement[] headerElements = BasicHeaderValueParser.parseElements(headerValue, null); if (ArrayUtils.isNotEmpty(headerElements)) { for (HeaderElement headerElement : headerElements) { for (NameValuePair parameter : headerElement.getParameters()) { if (StringUtils.equalsIgnoreCase(parameter.getName(), DETAIL)) { String spec = parameter.getValue(); if (StringUtils.isNotEmpty(spec)) { allSpecs.add(parameter.getValue()); } } } } } } } } // Try also from the matrix parameters: if (uri != null) { List<PathSegment> segments = uri.getPathSegments(); if (CollectionUtils.isNotEmpty(segments)) { PathSegment last = segments.get(segments.size() - 1); if (last != null) { MultivaluedMap<String, String> parameters = last.getMatrixParameters(); if (MapUtils.isNotEmpty(parameters)) { List<String> specs = parameters.get(DETAIL); if (CollectionUtils.isNotEmpty(specs)) { allSpecs.addAll(specs); } } } } } // Try also from the query parameters: if (uri != null) { MultivaluedMap<String, String> parameters = uri.getQueryParameters(); if (MapUtils.isNotEmpty(parameters)) { List<String> specs = parameters.get(DETAIL); if (CollectionUtils.isNotEmpty(specs)) { allSpecs.addAll(specs); } } } // Process all the obtained detail specifications: return parseDetails(allSpecs); }
From source file:org.ovirt.engine.api.common.util.DetailHelper.java
/** * Parses a string into the object that represents what to include. * * @param specs the specification of what to include or exclude * @return the set that represents what to include, which may be completely empty, but never * {@code null}//from w w w . j a va 2 s . co m */ private static Set<String> parseDetails(List<String> specs) { // In most cases the user won't give any detail specification, so it is worth to avoid creating an expensive // set in that case: if (CollectionUtils.isEmpty(specs)) { return Collections.singleton(MAIN); } // If the user gave a detail specification then we need first to add the default value and then parse it: Set<String> details = new HashSet<>(2); details.add(MAIN); if (CollectionUtils.isNotEmpty(specs)) { for (String spec : specs) { if (spec != null) { String[] chunks = spec.split("(?=[+-])"); if (ArrayUtils.isNotEmpty(chunks)) { for (String chunk : chunks) { chunk = chunk.trim(); if (chunk.startsWith("+")) { chunk = chunk.substring(1).trim(); if (StringUtils.isNotEmpty(chunk)) { details.add(chunk); } } else if (chunk.startsWith("-")) { chunk = chunk.substring(1).trim(); if (StringUtils.isNotEmpty(chunk)) { details.remove(chunk); } } else { details.add(chunk); } } } } } } return details; }
From source file:org.pentaho.metaverse.analyzer.kettle.step.httpclient.HTTPClientExternalResourceConsumer.java
@Override public Collection<IExternalResourceInfo> getResourcesFromRow(HTTP httpClientInput, RowMetaInterface rowMeta, Object[] row) {//from w ww .j a va2s . com Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>(); // For some reason the step doesn't return the StepMetaInterface directly, so go around it HTTPMeta meta = (HTTPMeta) httpClientInput.getStepMetaInterface(); if (meta == null) { meta = (HTTPMeta) httpClientInput.getStepMeta().getStepMetaInterface(); } if (meta != null) { try { String url; if (meta.isUrlInField()) { url = rowMeta.getString(row, meta.getUrlField(), null); } else { url = meta.getUrl(); } if (!Const.isEmpty(url)) { WebServiceResourceInfo resourceInfo = (WebServiceResourceInfo) ExternalResourceInfoFactory .createURLResource(url, true); if (ArrayUtils.isNotEmpty(meta.getHeaderField())) { for (int i = 0; i < meta.getHeaderField().length; i++) { String field = meta.getHeaderField()[i]; String label = meta.getHeaderParameter()[i]; resourceInfo.addHeader(label, rowMeta.getString(row, field, null)); } } if (ArrayUtils.isNotEmpty(meta.getArgumentField())) { for (int i = 0; i < meta.getArgumentField().length; i++) { String field = meta.getArgumentField()[i]; String label = meta.getArgumentParameter()[i]; resourceInfo.addParameter(label, rowMeta.getString(row, field, null)); } } resources.add(resourceInfo); } } catch (KettleException kve) { // TODO throw exception or ignore? } } return resources; }
From source file:org.pentaho.metaverse.analyzer.kettle.step.httpclient.HTTPClientStepAnalyzer.java
@Override protected Set<StepField> getUsedFields(HTTPMeta stepMeta) { Set<StepField> usedFields = new HashSet<>(); // add url field if (stepMeta.isUrlInField() && StringUtils.isNotEmpty(stepMeta.getUrlField())) { usedFields.addAll(createStepFields(stepMeta.getUrlField(), getInputs())); }//from www . j a v a2 s. co m // add parameters as used fields String[] parameterFields = stepMeta.getArgumentField(); if (ArrayUtils.isNotEmpty(parameterFields)) { for (String paramField : parameterFields) { usedFields.addAll(createStepFields(paramField, getInputs())); } } // add headers as used fields String[] headerFields = stepMeta.getHeaderField(); if (ArrayUtils.isNotEmpty(headerFields)) { for (String headerField : headerFields) { usedFields.addAll(createStepFields(headerField, getInputs())); } } return usedFields; }