use of org.apache.commons.lang3.StringUtils in project eol-globi-data by jhpoelen.
the class StudyImporterForHurlbert method importInteraction.
protected void importInteraction(Set<String> regions, Set<String> locales, Set<String> habitats, Record record, Study study, String preyTaxonName, String predatorName) throws StudyImporterException {
try {
Taxon predatorTaxon = new TaxonImpl(predatorName);
Specimen predatorSpecimen = nodeFactory.createSpecimen(study, predatorTaxon);
setBasisOfRecordAsLiterature(predatorSpecimen);
Taxon preyTaxon = new TaxonImpl(preyTaxonName);
String preyNameId = StringUtils.trim(columnValueOrNull(record, "Prey_Name_ITIS_ID"));
if (NumberUtils.isDigits(preyNameId)) {
preyTaxon.setExternalId(TaxonomyProvider.ITIS.getIdPrefix() + preyNameId);
}
Specimen preySpecimen = nodeFactory.createSpecimen(study, preyTaxon);
setBasisOfRecordAsLiterature(preySpecimen);
String preyStage = StringUtils.trim(columnValueOrNull(record, "Prey_Stage"));
if (StringUtils.isNotBlank(preyStage)) {
Term lifeStage = nodeFactory.getOrCreateLifeStage("HULBERT:" + StringUtils.replace(preyStage, " ", "_"), preyStage);
preySpecimen.setLifeStage(lifeStage);
}
String preyPart = StringUtils.trim(columnValueOrNull(record, "Prey_Part"));
if (StringUtils.isNotBlank(preyPart)) {
Term term = nodeFactory.getOrCreateBodyPart("HULBERT:" + StringUtils.replace(preyPart, " ", "_"), preyPart);
preySpecimen.setBodyPart(term);
}
Date date = addCollectionDate(record, study);
nodeFactory.setUnixEpochProperty(predatorSpecimen, date);
nodeFactory.setUnixEpochProperty(preySpecimen, date);
LocationImpl location = new LocationImpl(null, null, null, null);
String longitude = columnValueOrNull(record, "Longitude_dd");
String latitude = columnValueOrNull(record, "Latitude_dd");
if (NumberUtils.isNumber(latitude) && NumberUtils.isNumber(longitude)) {
try {
LatLng latLng = LocationUtil.parseLatLng(latitude, longitude);
String altitude = columnValueOrNull(record, "Altitude_mean_m");
Double altitudeD = NumberUtils.isNumber(altitude) ? Double.parseDouble(altitude) : null;
location = new LocationImpl(latLng.getLat(), latLng.getLng(), altitudeD, null);
} catch (InvalidLocationException e) {
getLogger().warn(study, "found invalid (lat,lng) pair: (" + latitude + "," + longitude + ")");
}
}
String locationRegion = columnValueOrNull(record, "Location_Region");
String locationSpecific = columnValueOrNull(record, "Location_Specific");
location.setLocality(StringUtils.join(Arrays.asList(locationRegion, locationSpecific), ":"));
Location locationNode = nodeFactory.getOrCreateLocation(location);
String habitat_type = columnValueOrNull(record, "Habitat_type");
List<Term> habitatList = Arrays.stream(StringUtils.split(StringUtils.defaultIfBlank(habitat_type, ""), ";")).map(StringUtils::trim).map(habitat -> new TermImpl(idForHabitat(habitat), habitat)).collect(Collectors.toList());
nodeFactory.addEnvironmentToLocation(locationNode, habitatList);
preySpecimen.caughtIn(locationNode);
predatorSpecimen.caughtIn(locationNode);
predatorSpecimen.ate(preySpecimen);
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to create interaction between [" + predatorName + "] and [" + preyTaxonName + "]", e);
}
}
use of org.apache.commons.lang3.StringUtils in project molgenis by molgenis.
the class SemanticSearchServiceHelper method createDisMaxQueryRuleForAttribute.
/**
* Create a disMaxJunc query rule based on the given search terms as well as the information from given ontology
* terms
*
* @return disMaxJunc queryRule
*/
public QueryRule createDisMaxQueryRuleForAttribute(Set<String> searchTerms, Collection<OntologyTerm> ontologyTerms) {
List<String> queryTerms = new ArrayList<>();
if (searchTerms != null) {
queryTerms.addAll(searchTerms.stream().filter(StringUtils::isNotBlank).map(this::processQueryString).collect(Collectors.toList()));
}
// Handle tags with only one ontologyterm
ontologyTerms.stream().filter(ontologyTerm -> !ontologyTerm.getIRI().contains(COMMA_CHAR)).forEach(ot -> queryTerms.addAll(parseOntologyTermQueries(ot)));
QueryRule disMaxQueryRule = createDisMaxQueryRuleForTerms(queryTerms);
// Handle tags with multiple ontologyterms
ontologyTerms.stream().filter(ontologyTerm -> ontologyTerm.getIRI().contains(COMMA_CHAR)).forEach(ot -> disMaxQueryRule.getNestedRules().add(createShouldQueryRule(ot.getIRI())));
return disMaxQueryRule;
}
use of org.apache.commons.lang3.StringUtils in project cloudbreak by hortonworks.
the class AmbariStackDetailsJsonToStackRepoDetailsConverter method convert.
@Override
public StackRepoDetails convert(AmbariStackDetailsJson source) {
StackRepoDetails repo = new StackRepoDetails();
Map<String, String> stack = new HashMap<>();
Map<String, String> util = new HashMap<>();
boolean baseRepoRequiredFieldsExists = Stream.of(source.getStackRepoId(), source.getStackBaseURL(), source.getUtilsRepoId(), source.getUtilsBaseURL()).noneMatch(StringUtils::isEmpty);
if (!isVdfRequiredFieldsExists(source) && !baseRepoRequiredFieldsExists) {
String msg = "The 'repositoryVersion', 'versionDefinitionFileUrl' or " + "'stackBaseURL', 'stackRepoId', 'utilsBaseUrl', 'utilsRepoId' fields must be specified!";
throw new BadRequestException(msg);
}
stack.put("repoid", source.getStackRepoId());
util.put("repoid", source.getUtilsRepoId());
if (baseRepoRequiredFieldsExists) {
String stackBaseURL = source.getStackBaseURL();
String utilsBaseURL = source.getUtilsBaseURL();
if (source.getOs() == null) {
stack.put(REDHAT_6, stackBaseURL);
stack.put(REDHAT_7, stackBaseURL);
stack.put(DEBIAN_9, stackBaseURL);
stack.put(UBUNTU_16, stackBaseURL);
util.put(REDHAT_6, utilsBaseURL);
util.put(REDHAT_7, utilsBaseURL);
util.put(DEBIAN_9, utilsBaseURL);
util.put(UBUNTU_16, utilsBaseURL);
} else {
stack.put(source.getOs(), stackBaseURL);
util.put(source.getOs(), utilsBaseURL);
}
}
if (!StringUtils.isEmpty(source.getRepositoryVersion())) {
stack.put(StackRepoDetails.REPOSITORY_VERSION, source.getRepositoryVersion());
stack.put("repoid", source.getStack());
}
if (!StringUtils.isEmpty(source.getVersionDefinitionFileUrl())) {
stack.put(StackRepoDetails.CUSTOM_VDF_REPO_KEY, source.getVersionDefinitionFileUrl());
}
if (!StringUtils.isEmpty(source.getMpackUrl())) {
stack.put(StackRepoDetails.MPACK_TAG, source.getMpackUrl());
}
repo.setStack(stack);
repo.setUtil(util);
repo.setEnableGplRepo(source.isEnableGplRepo());
repo.setVerify(source.getVerify());
repo.setHdpVersion(source.getVersion());
return repo;
}
use of org.apache.commons.lang3.StringUtils in project azure-tools-for-java by Microsoft.
the class AzureSdkTreePanel method loadData.
private void loadData(final Map<String, List<AzureSdkCategoryEntity>> categoryToServiceMap, final List<? extends AzureSdkServiceEntity> services, String... filters) {
final DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.model.getRoot();
root.removeAllChildren();
final Map<String, AzureSdkServiceEntity> serviceMap = services.stream().collect(Collectors.toMap(e -> getServiceKeyByName(e.getName()), e -> e));
final List<String> categories = categoryToServiceMap.keySet().stream().filter(StringUtils::isNotBlank).sorted((s1, s2) -> StringUtils.contains(s1, "Others") ? 1 : StringUtils.contains(s2, "Others") ? -1 : s1.compareTo(s2)).collect(Collectors.toList());
for (final String category : categories) {
// no feature found for current category
if (CollectionUtils.isEmpty(categoryToServiceMap.get(category)) || categoryToServiceMap.get(category).stream().allMatch(e -> Objects.isNull(serviceMap.get(getServiceKeyByName(e.getServiceName()))) || CollectionUtils.isEmpty(serviceMap.get(getServiceKeyByName(e.getServiceName())).getContent()))) {
continue;
}
// add features for current category
final MutableTreeNode categoryNode = new DefaultMutableTreeNode(category);
final boolean categoryMatched = this.isMatchedFilters(category, filters);
categoryToServiceMap.get(category).stream().sorted(Comparator.comparing(AzureSdkCategoryEntity::getServiceName)).forEach(categoryService -> {
final AzureSdkServiceEntity service = serviceMap.get(getServiceKeyByName(categoryService.getServiceName()));
this.loadServiceData(service, categoryService, categoryNode, filters);
});
if (ArrayUtils.isEmpty(filters) || categoryMatched || categoryNode.getChildCount() > 0) {
this.model.insertNodeInto(categoryNode, root, root.getChildCount());
}
}
this.model.reload();
if (ArrayUtils.isNotEmpty(filters)) {
TreeUtil.expandAll(this.tree);
}
TreeUtil.promiseSelectFirstLeaf(this.tree);
}
use of org.apache.commons.lang3.StringUtils in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class DataLayerBuilder method forAsset.
/**
* Get an AssetDataBuilder with standard asset data.
* This builder is suitable for most DAM Assets and pre-populates all required fields from the asset metadata.
*
* @param asset The asset used to initialize the AssetDataBuilder.
* @return A new AssetDataBuilder pre-initialized using the DAM asset metadata.
*/
public static AssetDataBuilder forAsset(@NotNull final Asset asset) {
return DataLayerBuilder.forAsset().withId(asset::getID).withFormat(asset::getMimeType).withUrl(asset::getPath).withLastModifiedDate(() -> new Date(Optional.of(asset.getLastModified()).filter(lastMod -> lastMod > 0).orElseGet(() -> Optional.ofNullable(asset.adaptTo(ValueMap.class)).map(vm -> vm.get(JcrConstants.JCR_CREATED, Calendar.class)).map(Calendar::getTimeInMillis).orElse(0L)))).withTags(() -> Optional.ofNullable(asset.getMetadataValueFromJcr(TagConstants.PN_TAGS)).filter(StringUtils::isNotEmpty).map(tagsValue -> tagsValue.split(",")).map(Arrays::stream).orElseGet(Stream::empty).filter(StringUtils::isNotEmpty).toArray(String[]::new)).withSmartTags(() -> {
Map<String, Object> smartTags = new HashMap<>();
Optional.ofNullable(asset.adaptTo(Resource.class)).map(assetResource -> assetResource.getChild(DamConstants.PREDICTED_TAGS)).map(predictedTagsResource -> {
for (Resource smartTagResource : predictedTagsResource.getChildren()) {
Optional.ofNullable(smartTagResource.adaptTo(ValueMap.class)).map(props -> Optional.ofNullable(props.get(AssetDataBuilder.SMARTTAG_NAME_PROP)).map(tagName -> Optional.ofNullable(smartTags.put((String) tagName, props.get(AssetDataBuilder.SMARTTAG_CONFIDENCE_PROP)))));
}
return Optional.empty();
});
return smartTags;
});
}
Aggregations