public static String makeLocationLabel(boolean discarded, String locationBarcode, String boxAlias, String position, String boxLocationBarcode) { if (discarded) { return "EMPTY"; } else if (boxAlias != null && position != null) { return (isStringEmptyOrNull(locationBarcode) ? "" : locationBarcode + ", ") + boxAlias + " - " + position + (isStringEmptyOrNull(boxLocationBarcode) ? "" : " (" + boxLocationBarcode + ")"); } else if (locationBarcode != null) { return locationBarcode; } else { return "Unknown"; } }
@Override public void setRoles(String[] roles) { StringBuilder roleString = new StringBuilder(); for (String role : roles) { if (!LimsUtils.isStringEmptyOrNull(role)) roleString.append(role); } this.roles = roleString.toString(); }
private static void setBigDecimal(@Nonnull Consumer<BigDecimal> setter, String value) { setter.accept(isStringEmptyOrNull(value) ? null : new BigDecimal(value)); }
public static Date parseDate(String dateString) { if (isStringEmptyOrNull(dateString)) { return null; } try { return getDateFormat().parse(dateString); } catch (ParseException e) { throw new IllegalArgumentException("Invalid date string"); } }
public static PaginationFilter distributed(String maybeDistributionDates) { if (!isStringEmptyOrNull(maybeDistributionDates)) { return parseDate(maybeDistributionDates, DateType.DISTRIBUTED); } return new PaginationFilter() { @Override public <T> void apply(PaginationFilterSink<T> sink, T item, Consumer<String> errorHandler) { sink.restrictPaginationByDistributed(item, errorHandler); } }; }
public static Date parseDateTime(String dateString) { if (isStringEmptyOrNull(dateString)) { return null; } try { return getDateTimeFormat().parse(dateString); } catch (ParseException e) { throw new IllegalArgumentException("Invalid datetime string"); } }
protected String getProperty(T object) { String alias = object.getAlias(); return isStringEmptyOrNull(alias) ? null : alias; }
@Override public List<BarcodableView> search(String query) { if (isStringEmptyOrNull(query)) throw new IllegalArgumentException("Search is empty"); @SuppressWarnings("unchecked") List<BarcodableView> results = currentSession().createCriteria(BarcodableView.class) .add(Restrictions.or( Restrictions.eq("identificationBarcode", query), Restrictions.eq("alias", query), Restrictions.eq("name", query))) .list(); return results; } }
@Override public Optional<DetailedSample> getEffectiveGroupIdSample() { for (DetailedSample sample = this; sample != null; sample = sample.getParent()) { String groupId = sample.getGroupId(); if (!LimsUtils.isStringEmptyOrNull(groupId)) return Optional.of(sample); } return Optional.empty(); }
public static void validateUrl(String maybeUrl, boolean allowEmptyUrl, Collection<ValidationError> errors) { if (isStringEmptyOrNull(maybeUrl) && allowEmptyUrl) return; URL url = parseUrl(maybeUrl, errors); if (url == null) { errors.add(new ValidationError(URL_FIELD, INVALID_URL)); return; } if (!allowedUrlSchemes.contains(url.getProtocol())) { errors.add(new ValidationError(URL_FIELD, INVALID_URL)); } }
public static void validateDistributionFields(boolean isDistributed, Date distributionDate, String distributionRecipient, Box box, Collection<ValidationError> errors) { if (isDistributed) { if (distributionDate == null) errors.add(new ValidationError("distributionDate", "Distribution date must be recorded for distributed item")); if (isStringEmptyOrNull(distributionRecipient)) errors.add(new ValidationError("distributionRecipient", "Distribution recipient must be recorded for distributed item")); } else { if (distributionDate != null) errors.add(new ValidationError("distributionDate", "Distribution date should be empty since item is not distributed")); if (!isStringEmptyOrNull(distributionRecipient)) errors.add(new ValidationError("distributionRecipient", "Distribution recipient should be empty since item is not distributed")); } }
/** Only freezers can have probes */ public void setProbeId(String probeId) { if (getLocationUnit() == null || getLocationUnit() != LocationUnit.FREEZER || isStringEmptyOrNull(probeId)) { this.probeId = null; } else { this.probeId = probeId; } }
@Override public Long create(ChangeLog changeLog) { checkNotNull(changeLog.getId(), "The entity this change log applies to must have an id."); checkNotNull(changeLog.getUser(), "The change log must be associated with a user."); checkArgument(!LimsUtils.isStringEmptyOrNull(changeLog.getSummary()), "The change log summary must not be empty."); if (changeLog.getTime() == null) { // Set the change log time stamp to the current time if it hasn't already been set. In the case of migration the time stamp // will be set to a historical time to accurately represent the time when the even occurred. changeLog.setTime(new Date()); } return (Long) currentSession().save(changeLog); }
private void applyOxfordNanoporeChanges(OxfordNanoporeRun target, OxfordNanoporeRun source) { target.setMinKnowVersion(isStringEmptyOrNull(source.getMinKnowVersion()) ? null : source.getMinKnowVersion()); target.setProtocolVersion(isStringEmptyOrNull(source.getProtocolVersion()) ? null : source.getProtocolVersion()); }
@Override public String getCurrentUsername() { User user = null; try { user = getCurrentUser(); } catch (IOException e) { user = null; } if (user == null || LimsUtils.isStringEmptyOrNull(user.getFullName())) { return UNKNOWN_USER; } else { return user.getFullName(); } }
@Override public long countLibrariesBySearch(String querystr) throws IOException { if (isStringEmptyOrNull(querystr)) { return count(); } else { Criteria criteria = currentSession().createCriteria(LibraryImpl.class); criteria.add(DbUtils.searchRestrictions(querystr, false, SEARCH_FIELDS)); return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); } }
public Sample build() { checkArgument(project != null, "A Project must be provided to create a Sample."); checkArgument(!LimsUtils.isStringEmptyOrNull(sampleType), "Must provide a sampleType to create a Sample"); checkArgument(!LimsUtils.isStringEmptyOrNull(scientificName), "Must provide a scientificName to create a Sample"); checkArgument(rootSampleClass != null, "A root SampleClass must be provided to create an Identity Sample."); log.debug("Create an Identity Sample."); SampleIdentityImpl i = new SampleIdentityImpl(); i.setName(name); i.setAlias(alias); i.setSampleClass(rootSampleClass); i.setVolume(volume); i.setDescription(description); i.setSampleType(sampleType); i.setProject(project); i.setScientificName(scientificName); i.setExternalName(externalName); i.setDonorSex(donorSex); i.setConsentLevel(consentLevel); i.inheritPermissions(project); return i; }
private static <T extends AbstractBoxableDto, U extends AbstractBoxable> AbstractBoxPosition makeBoxablePosition(@Nonnull T from, @Nonnull U to) { if (from.getBox() != null && (from.getBox().getId() != null || !isStringEmptyOrNull(from.getBoxPosition()))) { AbstractBoxPosition bp = to.getEntityType().makeBoxPosition(); bp.setBox(to(from.getBox())); bp.setPosition(from.getBoxPosition()); return bp; } return null; }
public static StorageLocation to(@Nonnull StorageLocationDto from) { StorageLocation location = new StorageLocation(); location.setId(from.getId()); location.setAlias(from.getAlias()); if (!LimsUtils.isStringEmptyOrNull(from.getIdentificationBarcode())) { location.setIdentificationBarcode(from.getIdentificationBarcode()); } if (!LimsUtils.isStringEmptyOrNull(from.getMapUrl())) { location.setMapUrl(from.getMapUrl()); } if (from.getParentLocationId() != null) { location.setParentLocation(new StorageLocation()); location.getParentLocation().setId(from.getParentLocationId()); } location.setLocationUnit(LocationUnit.valueOf(from.getLocationUnit())); location.setProbeId(from.getProbeId()); return location; }
private void loadChildEntities(Box box) throws IOException { if (box.getSize() != null) { box.setSize(getSize(box.getSize().getId())); } box.setUse(getUse(box.getUse().getId())); if (box.getStorageLocation() != null) { if (box.getStorageLocation().getId() > 0L) { box.setStorageLocation(storageLocationService.get(box.getStorageLocation().getId())); } else if (!LimsUtils.isStringEmptyOrNull(box.getStorageLocation().getIdentificationBarcode())) { box.setStorageLocation(storageLocationService.getByBarcode(box.getStorageLocation().getIdentificationBarcode())); } } }