List of usage examples for org.apache.commons.lang ArrayUtils isEmpty
public static boolean isEmpty(boolean[] array)
Checks if an array of primitive booleans is empty or null
.
From source file:org.betaconceptframework.astroboa.model.jaxb.CmsEntitySerialization.java
private String marshalEntity(CmsRepositoryEntity cmsRepositoryEntity, ResourceRepresentationType<?> resourceRepresentationType, boolean exportBinaryContent, boolean prettyPrint, String... propertyPathsToBeMarshalled) { if (cmsRepositoryEntity != null) { if (cmsRepositoryEntity instanceof ContentObject || cmsRepositoryEntity instanceof Topic || cmsRepositoryEntity instanceof Space || cmsRepositoryEntity instanceof RepositoryUser || cmsRepositoryEntity instanceof Taxonomy) { StringWriter writer = new StringWriter(); Marshaller marshaller = null; try { marshaller = createMarshaller(resourceRepresentationType, prettyPrint); if (cmsRepositoryEntity instanceof ContentObject) { if (!ArrayUtils.isEmpty(propertyPathsToBeMarshalled)) { marshaller.setProperty(AstroboaMarshaller.CMS_PROPERTIES_TO_BE_MARSHALLED, Arrays.asList(propertyPathsToBeMarshalled)); }//www . j a v a 2s. c o m //ContentObject needs special marshaling as JAXB does not have //enough information in order to initialize appropriate adapter for //ContentObject ContentObjectAdapter adapter = new ContentObjectAdapter(); adapter.setMarshaller(marshaller, exportBinaryContent, ArrayUtils.isEmpty(propertyPathsToBeMarshalled)); marshaller.setAdapter(adapter); ContentObjectType contentObjectType = marshaller.getAdapter(ContentObjectAdapter.class) .marshal((ContentObject) cmsRepositoryEntity); JAXBElement<ContentObjectType> contentObjectTypeJaxb = new JAXBElement<ContentObjectType>( ((ContentObject) cmsRepositoryEntity).getTypeDefinition().getQualifiedName(), ContentObjectType.class, null, contentObjectType); marshaller.marshal(contentObjectTypeJaxb, writer); } else { //Provide schema location marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, " " + BetaConceptNamespaceConstants.ASTROBOA_MODEL_DEFINITION_URI + " " + SchemaUtils.buildSchemaLocationForAstroboaModelSchemaAccordingToActiveClient()); marshaller.marshal(cmsRepositoryEntity, writer); } } catch (Exception e) { throw new CmsException(e); } finally { marshaller = null; } return writer.toString(); } else { throw new CmsException("Creating XML for entity type " + cmsRepositoryEntity.getClass().getName() + " is not supported"); } } throw new CmsException("No entity is provided. Unable to create xml"); }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.ContentObjectResource.java
private ContentObjectCriteria buildCriteria(String cmsQuery, Integer offset, Integer limit, String commaDelimitedProjectionPaths, String orderBy, boolean prettyPrint) { //Build ContentObject criteria ContentObjectCriteria contentObjectCriteria = CmsCriteriaFactory.newContentObjectCriteria(); if (offset == null || offset < 0) { contentObjectCriteria.setOffset(0); } else {/*from w w w .j av a 2 s . c om*/ contentObjectCriteria.setOffset(offset); } if (limit == null || limit < 0) { contentObjectCriteria.setLimit(50); } else { contentObjectCriteria.setLimit(limit); } if (StringUtils.isNotBlank(commaDelimitedProjectionPaths)) { contentObjectCriteria.getPropertyPathsWhichWillBePreLoaded() .addAll(Arrays.asList(commaDelimitedProjectionPaths.split(CmsConstants.COMMA))); } else { contentObjectCriteria.getRenderProperties().renderAllContentObjectProperties(true); } contentObjectCriteria.getRenderProperties().prettyPrint(prettyPrint); //Parse query if (StringUtils.isNotBlank(cmsQuery)) { CriterionFactory.parse(cmsQuery, contentObjectCriteria); } else { logger.warn( "No query parameter was found. All content objects will be returned according to limit {} and offset {}", contentObjectCriteria.getLimit(), contentObjectCriteria.getOffset()); } //Parse order by //Order by value expects to follow pattern // property.path asc,property.path2 desc,property.path3 if (StringUtils.isNotBlank(orderBy)) { String[] propertyPathsWithOrder = StringUtils.split(orderBy, ","); if (!ArrayUtils.isEmpty(propertyPathsWithOrder)) { for (String propertyWithOrder : propertyPathsWithOrder) { String[] propertyItems = StringUtils.split(propertyWithOrder, " "); if (!ArrayUtils.isEmpty(propertyItems) && propertyItems.length == 2) { String property = propertyItems[0]; String order = propertyItems[1]; //Check to see if order is valid if (StringUtils.isNotBlank(property)) { if (StringUtils.equals("desc", order)) { contentObjectCriteria.addOrderProperty(property, Order.descending); } else { //Any other value (even invalid) set default order which is ascending contentObjectCriteria.addOrderProperty(property, Order.ascending); } } } } } } return contentObjectCriteria; }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.TopicResource.java
private TopicCriteria buildCriteria(String cmsQuery, Integer offset, Integer limit, String orderBy, boolean prettyPrint) { //Build Topic criteria TopicCriteria topicCriteria = CmsCriteriaFactory.newTopicCriteria(); if (offset == null || offset < 0) { topicCriteria.setOffset(0);//from w w w . j a v a 2 s. c o m } else { topicCriteria.setOffset(offset); } if (limit == null || limit < 0) { topicCriteria.setLimit(50); } else { topicCriteria.setLimit(limit); } topicCriteria.getRenderProperties().renderAllContentObjectProperties(true); topicCriteria.getRenderProperties().prettyPrint(prettyPrint); //Parse query if (StringUtils.isNotBlank(cmsQuery)) { CriterionFactory.parse(cmsQuery, topicCriteria); } else { logger.warn("No query parameter was found. All topics will be returned according to limit and offset"); } //Parse order by //Order by value expects to follow pattern // property.path asc,property.path2 desc,property.path3 if (StringUtils.isNotBlank(orderBy)) { String[] propertyPathsWithOrder = StringUtils.split(orderBy, ","); if (!ArrayUtils.isEmpty(propertyPathsWithOrder)) { for (String propertyWithOrder : propertyPathsWithOrder) { String[] propertyItems = StringUtils.split(propertyWithOrder, " "); if (!ArrayUtils.isEmpty(propertyItems) && propertyItems.length == 2) { String property = propertyItems[0]; String order = propertyItems[1]; //Check to see if order is valid if (StringUtils.isNotBlank(property)) { if (StringUtils.equals("desc", order)) { topicCriteria.addOrderProperty(property, Order.descending); } else { //Any other value (even invalid) set default order which is ascending topicCriteria.addOrderProperty(property, Order.ascending); } } } } } } return topicCriteria; }
From source file:org.betaconceptframework.astroboa.test.engine.security.ContentObjectDeleteSecurityTest.java
private Object executeMethodOnContentService(String methodName, String contentObjectId, boolean logException, Object[] methodArgumentsApartFromContentObjectId, Class<?>... parameterTypes) throws Throwable { List<Object> objectParameters = new ArrayList<Object>(); objectParameters.add(contentObjectId); if (!ArrayUtils.isEmpty(methodArgumentsApartFromContentObjectId)) { objectParameters.addAll(Arrays.asList(methodArgumentsApartFromContentObjectId)); }//from w w w . jav a 2 s .c om Method method = contentService.getClass().getMethod(methodName, parameterTypes); try { if (!logException) { TestLogPolicy.setLevelForLogger(Level.FATAL, SecureContentObjectDeleteAspect.class.getName()); } return method.invoke(contentService, objectParameters.toArray()); } catch (Exception t) { if (logException) { throw new CmsException(methodName + " " + parameterTypes + objectParameters.toArray().toString(), t); } else { if (t instanceof InvocationTargetException) { throw t.getCause(); } else { throw t; } } } finally { if (!logException) { TestLogPolicy.setDefaultLevelForLogger(SecureContentObjectSaveAspect.class.getName()); } } }
From source file:org.betaconceptframework.astroboa.test.engine.security.ContentObjectSaveSecurityTest.java
private ContentObject executeMethodOnContentService(String methodName, ContentObject contentObject, boolean logException, Object[] methodArgumentsApartFromContentObjectId, Class<?>... parameterTypes) throws Throwable { List<Object> objectParameters = new ArrayList<Object>(); objectParameters.add(contentObject); if (!ArrayUtils.isEmpty(methodArgumentsApartFromContentObjectId)) { objectParameters.addAll(Arrays.asList(methodArgumentsApartFromContentObjectId)); }//from w ww .j a v a 2s . c om Method method = contentService.getClass().getMethod(methodName, parameterTypes); try { if (!logException) { TestLogPolicy.setLevelForLogger(Level.ERROR, SecureContentObjectSaveAspect.class.getName()); } return (ContentObject) method.invoke(contentService, objectParameters.toArray()); } catch (Exception t) { if (logException) { throw new CmsException(methodName + " " + parameterTypes + objectParameters.toArray().toString(), t); } else { if (t instanceof InvocationTargetException) { throw t.getCause(); } else { throw t; } } } finally { if (!logException) { TestLogPolicy.setDefaultLevelForLogger(SecureContentObjectSaveAspect.class.getName()); } } }
From source file:org.betaconceptframework.astroboa.test.engine.security.ContentObjectSecurityTest.java
private ContentObject executeMethodOnContentService(ContentObjectMethodDeclaration contentObjectMethod, String contentObjectIdentifier) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { final String methodName = contentObjectMethod.getName(); final Class<?>[] parameterTypes = contentObjectMethod.getParameterTypes(); List<Object> objectParameters = new ArrayList<Object>(); objectParameters.add(contentObjectIdentifier); if (!ArrayUtils.isEmpty(contentObjectMethod.getParameterValues())) { objectParameters.addAll(Arrays.asList(contentObjectMethod.getParameterValues())); }//from ww w . ja v a 2 s.com Method method = contentService.getClass().getMethod(methodName, parameterTypes); try { Object result = method.invoke(contentService, objectParameters.toArray()); if (result != null) { if (result instanceof String) { //Method may return string. //Create ContentObject from import ImportConfiguration configuration = ImportConfiguration.object() .persist(PersistMode.DO_NOT_PERSIST).build(); return importDao.importContentObject((String) result, configuration); } else if (result instanceof CmsOutcome) { final long count = ((CmsOutcome) result).getCount(); if (count == 1) { return ((CmsOutcome<ContentObject>) result).getResults().get(0); } else if (count == 0) { return null; } else { throw new CmsException("Returned more than one content objects"); } } } return (ContentObject) result; } catch (Exception t) { throw new CmsException(methodName + " " + parameterTypes + objectParameters.toArray().toString(), t); } }
From source file:org.bigmouth.nvwa.network.http.HttpClientHelper.java
public static void printHeaders(org.apache.http.Header[] headers) { if (ArrayUtils.isEmpty(headers)) return;/*from w w w . j av a 2s . c om*/ for (org.apache.http.Header header : headers) { if (LOGGER.isInfoEnabled()) { LOGGER.info(header.getName() + " = " + header.getValue()); } } }
From source file:org.bigmouth.nvwa.network.http.utils.HttpUtils.java
private static HttpResponse access(HttpRequest request) throws UnexpectStatusCodeException, HttpException { String url = request.getUrl(); if (StringUtils.isBlank(url)) throw new IllegalArgumentException("url"); HttpClient http = HttpClientHelper.http(request.getTimeout()); try {//from w ww . java 2s. c o m if (LOGGER.isDebugEnabled()) { LOGGER.debug("-{}", url); } Method method = request.getMethod(); HttpRequestBase requestBase = null; List<NameValuePair> pairs = request.getPairs(); List<Header> headers = request.getHeaders(); if (method == Method.POST) { HttpPost post = HttpClientHelper.post(url); byte[] entity = request.getEntity(); if (!CollectionUtils.isEmpty(pairs)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("?-{}", pairs); } HttpClientHelper.addPair(post, pairs.toArray(new NameValuePair[0])); } if (!ArrayUtils.isEmpty(entity)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("?-{}", entity); } HttpClientHelper.addByteArrayEntity(post, entity); } requestBase = post; } else if (method == Method.GET) { HttpGet get = HttpClientHelper.get(url); if (!CollectionUtils.isEmpty(pairs)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("?-{}", pairs); } HttpClientHelper.addPair(get, pairs.toArray(new NameValuePair[0])); } requestBase = get; } else { throw new IllegalArgumentException("Not supported method type: " + method); } if (!CollectionUtils.isEmpty(headers)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("-{}", headers); } for (Header header : headers) { requestBase.addHeader(header); } } long start = System.currentTimeMillis(); org.apache.http.HttpResponse httpResponse = http.execute(requestBase); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" {} ", (System.currentTimeMillis() - start)); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != request.getExpectStatusCode()) { if (request.isThrowUnexpectStatusCode()) throw new UnexpectStatusCodeException(statusCode); } String response = HttpClientHelper.getResponseBody(httpResponse, false, request.getCharset()); Header[] allHeaders = httpResponse.getAllHeaders(); HttpResponse hrp = new HttpResponse(); hrp.addAllHeaders(allHeaders); hrp.setEntityString(response); hrp.setStatusCode(statusCode); return hrp; } catch (Exception e) { throw new HttpException(e); } finally { http.getConnectionManager().shutdown(); } }
From source file:org.bigmouth.nvwa.pay.service.callback.wx.WxCallback.java
public WxCallbackResponse callback(byte[] entity) { if (ArrayUtils.isEmpty(entity)) { throw new CallbackException("data has empty!"); }/*w ww . j a v a2 s . c o m*/ WxCallbackArgument argument = WxCallbackArgument.of(StringHelper.convert(entity)); if (null == argument) { throw new CallbackAnalysisException(); } if (LOGGER.isInfoEnabled()) { LOGGER.info("Receive callback from Wx, Request parameters are [{}]", argument); } WxCallbackResponse response = new WxCallbackResponse(); response.setArgument(argument); return response; }
From source file:org.dspace.app.xmlui.aspect.discovery.AbstractSearch.java
/** * Render the given item, all metadata is added to the given list, which metadata will be rendered where depends on the xsl * @param dspaceObjectsList a list of DSpace objects * @param item the DSpace item to be rendered * @param highlightedResults the highlighted results * @throws WingException/*from w ww . ja v a 2 s .co m*/ * @throws SQLException Database failure in services this calls */ protected void renderItem(org.dspace.app.xmlui.wing.element.List dspaceObjectsList, Item item, DiscoverResult.DSpaceObjectHighlightResult highlightedResults) throws WingException, SQLException { org.dspace.app.xmlui.wing.element.List itemList = dspaceObjectsList.addList(item.getHandle() + ":item"); MetadataField[] metadataFields = MetadataField.findAll(context); for (MetadataField metadataField : metadataFields) { //Retrieve the schema for this field String schema = MetadataSchema.find(context, metadataField.getSchemaID()).getName(); //Check if our field isn't hidden if (!MetadataExposure.isHidden(context, schema, metadataField.getElement(), metadataField.getQualifier())) { //Check if our metadata field is highlighted StringBuilder metadataKey = new StringBuilder(); metadataKey.append(schema).append(".").append(metadataField.getElement()); if (metadataField.getQualifier() != null) { metadataKey.append(".").append(metadataField.getQualifier()); } StringBuilder itemName = new StringBuilder(); itemName.append(item.getHandle()).append(":").append(metadataKey.toString()); Metadatum[] itemMetadata = item.getMetadata(schema, metadataField.getElement(), metadataField.getQualifier(), Item.ANY); if (!ArrayUtils.isEmpty(itemMetadata)) { org.dspace.app.xmlui.wing.element.List metadataFieldList = itemList .addList(itemName.toString()); for (Metadatum metadataValue : itemMetadata) { String value = metadataValue.value; addMetadataField(highlightedResults, metadataKey.toString(), metadataFieldList, value); } } } } //Check our highlighted results, we may need to add non-metadata (like our full text) if (highlightedResults != null) { //Also add the full text snippet (if available !) List<String> fullSnippets = highlightedResults.getHighlightResults("fulltext"); if (CollectionUtils.isNotEmpty(fullSnippets)) { StringBuilder itemName = new StringBuilder(); itemName.append(item.getHandle()).append(":").append("fulltext"); org.dspace.app.xmlui.wing.element.List fullTextFieldList = itemList.addList(itemName.toString()); for (String snippet : fullSnippets) { addMetadataField(fullTextFieldList, snippet); } } } }