List of usage examples for org.apache.commons.lang3 StringUtils trimToNull
public static String trimToNull(final String str)
Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null .
From source file:hoot.services.writers.review.ReviewPrepareDbWriter.java
protected boolean parseElementUniqueIdTags(final long mapId) throws Exception { final String logMsgStart = "Parsing element unique ID tags for map with ID: " + mapId + ". Step 2 of 4."; log.info(logMsgStart);//from ww w. j ava 2 s . c o m uniqueIdsParsed = 0; idMappingRecordWritten = false; List<ElementIdMappings> elementIdMappingRecordsToInsert = new ArrayList<ElementIdMappings>(); //create this outside of the batch read loop, since we need to maintain a list of unique //ID's parsed over the entire map's set of reviewable records Set<String> elementIds = new HashSet<String>(); for (ElementType elementType : ElementType.values()) { if (!elementType.equals(ElementType.Changeset)) { //final Element prototype = ElementFactory.getInstance().create(elementType, conn); int numElementsReturned = Integer.MAX_VALUE; int elementIndex = 0; while (numElementsReturned > 0) { //get all reviewable elements final Map<Long, Object> reviewableElementRecords = getParseableElementRecords(mapId, elementType, maxRecordSelectSize, elementIndex); numElementsReturned = reviewableElementRecords.size(); elementIndex += numElementsReturned; for (Map.Entry<Long, Object> reviewableElementRecordEntry : reviewableElementRecords .entrySet()) { final long osmElementId = reviewableElementRecordEntry.getKey(); final Object reviewableElementRecord = reviewableElementRecordEntry.getValue(); final Map<String, String> tags = PostgresUtils.postgresObjToHStore((PGobject) MethodUtils .invokeMethod(reviewableElementRecord, "getTags", new Object[] {})); String uniqueElementId = StringUtils.trimToNull(tags.get("uuid")); if (uniqueElementId == null) { log.warn("Invalid UUID: " + uniqueElementId + " for map with ID: " + mapId + ". Skipping adding unique ID record..."); } //TODO: make this a batch query somehow else if (new SQLQuery(conn, DbUtils.getConfiguration(mapId)).from(elementIdMappings) .where(elementIdMappings.mapId.eq(mapId) .and(elementIdMappings.elementId.eq(uniqueElementId))) .count() > 0) { log.info("UUID: " + uniqueElementId + " for map with ID: " + mapId + " already exists. " + "Skipping adding unique ID record..."); } else { if (elementIds.add(uniqueElementId)) //don't add duplicates { log.debug("Adding UUID: " + uniqueElementId); elementIdMappingRecordsToInsert.add(createElementIdMappingRecord(uniqueElementId, osmElementId, elementType, mapId)); flushIdMappingRecords(elementIdMappingRecordsToInsert, maxRecordBatchSize, logMsgStart); } else { log.debug("Duplicate element ID: " + uniqueElementId.toString() + " for map with ID: " + mapId + ". Skipping adding unique ID record..."); } } } } } } //final flush flushIdMappingRecords(elementIdMappingRecordsToInsert, 0, logMsgStart); log.debug("Wrote " + elementIds.size() + " ID mappings."); return idMappingRecordWritten; }
From source file:com.hubrick.vertx.s3.client.S3Client.java
/** * For manual handling of multipart uploads. Upload the next part. * Note you have manually to keep track of the sequential {@link ContinueMultipartUploadRequest#partNumber} * * @param bucket The bucket * @param key The key of the final file * @param continueMultipartUploadRequest The request * @param handler Success handler * @param exceptionHandler Exception handler *//* ww w . ja v a 2 s .c om*/ public void continueMultipartUpload(String bucket, String key, ContinueMultipartUploadRequest continueMultipartUploadRequest, Handler<Response<ContinueMultipartUploadResponseHeaders, Void>> handler, Handler<Throwable> exceptionHandler) { checkNotNull(StringUtils.trimToNull(bucket), "bucket must not be null"); checkNotNull(StringUtils.trimToNull(key), "key must not be null"); checkNotNull(continueMultipartUploadRequest, "continueMultipartUploadRequest must not be null"); checkNotNull(handler, "handler must not be null"); checkNotNull(exceptionHandler, "exceptionHandler must not be null"); final S3ClientRequest request = createContinueMultipartUploadRequest(bucket, key, continueMultipartUploadRequest, new HeadersResponseHandler("continueMultipartUpload", jaxbUnmarshaller, new ContinueMultipartUploadResponseHeadersMapper(), handler, exceptionHandler, false)); request.exceptionHandler(exceptionHandler); request.end(continueMultipartUploadRequest.getData()); }
From source file:ltistarter.lti.LTIRequest.java
/** * @param request the incoming request//w w w . ja v a 2s . c om * @return true if this is a valid LTI request */ public static boolean isLTIRequest(ServletRequest request) { boolean valid = false; String ltiVersion = StringUtils.trimToNull(request.getParameter(LTI_VERSION)); String ltiMessageType = StringUtils.trimToNull(request.getParameter(LTI_MESSAGE_TYPE)); if (ltiMessageType != null && ltiVersion != null) { boolean goodMessageType = LTI_MESSAGE_TYPE_BASIC.equals(ltiMessageType) || LTI_MESSAGE_TYPE_PROXY_REG.equals(ltiMessageType); boolean goodLTIVersion = LTI_VERSION_1P0.equals(ltiVersion) || LTI_VERSION_2P0.equals(ltiVersion); valid = goodMessageType && goodLTIVersion; } // resource_link_id is also required return valid; }
From source file:hoot.services.controllers.ingest.CustomScriptResource.java
private JSONObject saveScript(final String name, final String description, final String content) throws Exception { if (StringUtils.trimToNull(name) == null) { log.error("Invalid input script name: " + name); return null; }//from w ww . j av a 2 s . c om if (StringUtils.trimToNull(content) == null) { log.error("Invalid input script content."); return null; } boolean canExport = validateExport(content); if (!uploadDirExists()) { FileUtils.forceMkdir(getUploadDir()); } File fScript = new File(scriptFolder + "/" + name + ".js"); if (!fScript.exists()) { fScript.createNewFile(); } String header = headerStart; JSONObject oHeader = new JSONObject(); oHeader.put("NAME", name); oHeader.put("DESCRIPTION", description); oHeader.put("CANEXPORT", canExport); header += oHeader.toString(); header += headerEnd; FileUtils.writeStringToFile(fScript, header + content); log.debug("Saved script: " + name); return oHeader; }
From source file:alfio.manager.AdminReservationManager.java
private void updateExtRefAndLocking(int categoryId, Attendee attendee, Integer ticketId) { try {/*from ww w .j a v a 2 s .co m*/ ticketRepository.updateExternalReferenceAndLocking(ticketId, categoryId, StringUtils.trimToNull(attendee.getReference()), attendee.isReassignmentForbidden()); } catch (DataIntegrityViolationException ex) { log.warn("Duplicate found for external reference: " + attendee.getReference() + " and ticketID: " + ticketId); throw new DuplicateReferenceException("Duplicated Reference: " + attendee.getReference(), ex); } }
From source file:com.hubrick.vertx.s3.client.S3Client.java
/** * For manual handling of multipart uploads. Complete the multipart upload. * * @param bucket The bucket * @param key The key of the final file * @param completeMultipartUploadRequest The request * @param handler Success handler * @param exceptionHandler Exception handler *//* w ww .j ava2 s.co m*/ public void completeMultipartUpload(String bucket, String key, CompleteMultipartUploadRequest completeMultipartUploadRequest, Handler<Response<CompleteMultipartUploadResponseHeaders, CompleteMultipartUploadResponse>> handler, Handler<Throwable> exceptionHandler) { checkNotNull(StringUtils.trimToNull(bucket), "bucket must not be null"); checkNotNull(StringUtils.trimToNull(key), "key must not be null"); checkNotNull(completeMultipartUploadRequest, "completeMultipartUploadRequest must not be null"); checkNotNull(handler, "handler must not be null"); checkNotNull(exceptionHandler, "exceptionHandler must not be null"); final S3ClientRequest request = createCompleteMultipartUploadRequest(bucket, key, completeMultipartUploadRequest, new XmlBodyResponseHandler<>("completeMultipartUpload", jaxbUnmarshaller, new CompleteMultipartUploadResponseHeadersMapper(), handler, exceptionHandler)); request.exceptionHandler(exceptionHandler); try { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); jaxbMarshaller.marshal(completeMultipartUploadRequest, outputStream); request.putHeader(Headers.CONTENT_TYPE, "application/xml"); request.end(Buffer.buffer(outputStream.toByteArray())); } catch (JAXBException e) { exceptionHandler.handle(e); } }
From source file:de.micromata.genome.gwiki.pagelifecycle_1_0.action.WorkflowPopupActionBean.java
/** * applies change comment to page//from w ww . java 2 s. c om */ private void applyComment() { Map<String, GWikiArtefakt<?>> map = new HashMap<String, GWikiArtefakt<?>>(); page.collectParts(map); GWikiArtefakt<?> artefakt = map.get("ChangeComment"); if (artefakt instanceof GWikiChangeCommentArtefakt == false) { return; } GWikiChangeCommentArtefakt commentArtefakt = (GWikiChangeCommentArtefakt) artefakt; String oldText = commentArtefakt.getStorageData(); String ntext; String uname = wikiContext.getWikiWeb().getAuthorization().getCurrentUserName(wikiContext); int prevVersion = page.getElementInfo().getProps().getIntValue(GWikiPropKeys.VERSION, 0); if (StringUtils.isNotBlank(comment) == true) { Date now = new Date(); ntext = "{changecomment:modifiedBy=" + uname + "|modifiedAt=" + GWikiProps.date2string(now) + "|version=" + (prevVersion + 1) + "}\n" + comment + "\n{changecomment}\n" + StringUtils.defaultString(oldText); } else { ntext = oldText; } ntext = StringUtils.trimToNull(ntext); commentArtefakt.setStorageData(ntext); }
From source file:com.hubrick.vertx.s3.client.S3Client.java
/** * For manual handling of multipart uploads. Abort the multipart upload. * * @param bucket The bucket * @param key The key of the final file * @param abortMultipartUploadRequest The request * @param handler Success handler * @param exceptionHandler Exception handler *//*from w ww . jav a2 s. com*/ public void abortMultipartUpload(String bucket, String key, AbortMultipartUploadRequest abortMultipartUploadRequest, Handler<Response<CommonResponseHeaders, Void>> handler, Handler<Throwable> exceptionHandler) { checkNotNull(StringUtils.trimToNull(bucket), "bucket must not be null"); checkNotNull(StringUtils.trimToNull(key), "key must not be null"); checkNotNull(abortMultipartUploadRequest, "abortMultipartUploadRequest must not be null"); checkNotNull(handler, "handler must not be null"); checkNotNull(exceptionHandler, "exceptionHandler must not be null"); final S3ClientRequest request = createAbortMultipartUploadRequest(bucket, key, abortMultipartUploadRequest, new HeadersResponseHandler<>("abortMultipartUpload", jaxbUnmarshaller, new CommonResponseHeadersMapper(), handler, exceptionHandler, false)); request.exceptionHandler(exceptionHandler); request.end(); }
From source file:com.hubrick.vertx.s3.client.S3Client.java
public void copyObject(String sourceBucket, String sourceKey, String destinationBucket, String destinationKey, CopyObjectRequest copyObjectRequest, Handler<Response<CopyObjectResponseHeaders, CopyObjectResponse>> handler, Handler<Throwable> exceptionHandler) { checkNotNull(StringUtils.trimToNull(sourceBucket), "sourceBucket must not be null"); checkNotNull(StringUtils.trimToNull(sourceKey), "sourceKey must not be null"); checkNotNull(StringUtils.trimToNull(destinationBucket), "destinationBucket must not be null"); checkNotNull(StringUtils.trimToNull(destinationKey), "destinationKey must not be null"); checkNotNull(copyObjectRequest, "copyObjectRequest must not be null"); checkNotNull(handler, "handler must not be null"); checkNotNull(exceptionHandler, "exceptionHandler must not be null"); final S3ClientRequest request = createCopyRequest(sourceBucket, sourceKey, destinationBucket, destinationKey, copyObjectRequest, new XmlBodyResponseHandler<>("copyObject", jaxbUnmarshaller, new CopyResponseHeadersMapper(), handler, exceptionHandler)); request.exceptionHandler(exceptionHandler); request.end();//ww w . j a va2s . c o m }
From source file:com.hubrick.vertx.s3.client.S3Client.java
public void deleteObject(String bucket, String key, DeleteObjectRequest deleteObjectRequest, Handler<Response<CommonResponseHeaders, Void>> handler, Handler<Throwable> exceptionHandler) { checkNotNull(StringUtils.trimToNull(bucket), "bucket must not be null"); checkNotNull(StringUtils.trimToNull(key), "key must not be null"); checkNotNull(deleteObjectRequest, "deleteObjectRequest must not be null"); checkNotNull(handler, "handler must not be null"); checkNotNull(exceptionHandler, "exceptionHandler must not be null"); final S3ClientRequest request = createDeleteRequest(bucket, key, deleteObjectRequest, new HeadersResponseHandler("deleteObject", jaxbUnmarshaller, new CommonResponseHeadersMapper(), handler, exceptionHandler, false)); request.exceptionHandler(exceptionHandler); request.end();// w w w .j a v a2s .c o m }