Search in sources :

Example 1 with StringUtils

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);
    }
}
Also used : TsvParser(com.univocity.parsers.tsv.TsvParser) DateUtil(org.eol.globi.util.DateUtil) StringUtils(org.apache.commons.lang.StringUtils) CitationUtil(org.globalbioticinteractions.dataset.CitationUtil) Arrays(java.util.Arrays) Record(com.univocity.parsers.common.record.Record) Term(org.eol.globi.domain.Term) Specimen(org.eol.globi.domain.Specimen) Location(org.eol.globi.domain.Location) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) LocationImpl(org.eol.globi.domain.LocationImpl) HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) HashSet(java.util.HashSet) TaxonImpl(org.eol.globi.domain.TaxonImpl) Map(java.util.Map) LatLng(org.eol.globi.geo.LatLng) TaxonomyProvider(org.eol.globi.domain.TaxonomyProvider) Taxon(org.eol.globi.domain.Taxon) InvalidLocationException(org.eol.globi.util.InvalidLocationException) DateTime(org.joda.time.DateTime) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TsvParserSettings(com.univocity.parsers.tsv.TsvParserSettings) List(java.util.List) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Study(org.eol.globi.domain.Study) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) ArrayUtils(org.apache.commons.lang.ArrayUtils) InputStream(java.io.InputStream) InvalidLocationException(org.eol.globi.util.InvalidLocationException) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Term(org.eol.globi.domain.Term) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) Specimen(org.eol.globi.domain.Specimen) StringUtils(org.apache.commons.lang.StringUtils) LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) Location(org.eol.globi.domain.Location)

Example 2 with StringUtils

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;
}
Also used : NGramDistanceAlgorithm(org.molgenis.semanticsearch.string.NGramDistanceAlgorithm) Stemmer(org.molgenis.semanticsearch.string.Stemmer) java.util(java.util) EntityTypeMetadata(org.molgenis.data.meta.model.EntityTypeMetadata) TermFrequencyService(org.molgenis.ontology.core.ic.TermFrequencyService) Operator(org.molgenis.data.QueryRule.Operator) QueryImpl(org.molgenis.data.support.QueryImpl) StringUtils(org.apache.commons.lang3.StringUtils) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ENTITY_TYPE_META_DATA(org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA) MolgenisDataAccessException(org.molgenis.data.MolgenisDataAccessException) COMPOUND(org.molgenis.data.meta.AttributeType.COMPOUND) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Objects.requireNonNull(java.util.Objects.requireNonNull) DataService(org.molgenis.data.DataService) AttributeMetadata(org.molgenis.data.meta.model.AttributeMetadata) OntologyService(org.molgenis.ontology.core.service.OntologyService) Arrays.stream(java.util.Arrays.stream) QueryRule(org.molgenis.data.QueryRule) Entity(org.molgenis.data.Entity) QueryRule(org.molgenis.data.QueryRule)

Example 3 with StringUtils

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;
}
Also used : StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 4 with StringUtils

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);
}
Also used : Arrays(java.util.Arrays) AllIcons(com.intellij.icons.AllIcons) AzureSdkCategoryService(com.microsoft.azure.toolkit.intellij.azuresdk.service.AzureSdkCategoryService) Presentation(com.intellij.openapi.actionSystem.Presentation) StringUtils(org.apache.commons.lang3.StringUtils) Map(java.util.Map) CommonActionsManager(com.intellij.ide.CommonActionsManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreePath(javax.swing.tree.TreePath) TailingDebouncer(com.microsoft.azure.toolkit.lib.common.utils.TailingDebouncer) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Collectors(java.util.stream.Collectors) DefaultTreeExpander(com.intellij.ide.DefaultTreeExpander) MutableTreeNode(javax.swing.tree.MutableTreeNode) JBScrollPane(com.intellij.ui.components.JBScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Objects(java.util.Objects) IdeBundle(com.intellij.ide.IdeBundle) RelativeFont(com.intellij.ui.RelativeFont) List(java.util.List) SimpleTree(com.intellij.ui.treeStructure.SimpleTree) ActionPlaces(com.intellij.openapi.actionSystem.ActionPlaces) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Optional(java.util.Optional) TextDocumentListenerAdapter(com.microsoft.azure.toolkit.intellij.common.TextDocumentListenerAdapter) NotNull(org.jetbrains.annotations.NotNull) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) Setter(lombok.Setter) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Getter(lombok.Getter) ActionToolbarImpl(com.intellij.openapi.actionSystem.impl.ActionToolbarImpl) SearchTextField(com.intellij.ui.SearchTextField) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AzureSdkLibraryService(com.microsoft.azure.toolkit.intellij.azuresdk.service.AzureSdkLibraryService) ActivityTracker(com.intellij.ide.ActivityTracker) Tree(com.intellij.ui.treeStructure.Tree) TreeUtil(com.intellij.util.ui.tree.TreeUtil) AnimatedIcon(com.intellij.ui.AnimatedIcon) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) IOException(java.io.IOException) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) RenderingUtil(com.intellij.ui.render.RenderingUtil) Consumer(java.util.function.Consumer) AzureSdkFeatureEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) Comparator(java.util.Comparator) javax.swing(javax.swing) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StringUtils(org.apache.commons.lang3.StringUtils) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 5 with StringUtils

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;
    });
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Arrays(java.util.Arrays) JcrConstants(org.apache.jackrabbit.JcrConstants) Asset(com.day.cq.dam.api.Asset) ImageData(com.adobe.cq.wcm.core.components.models.datalayer.ImageData) Date(java.util.Date) AssetData(com.adobe.cq.wcm.core.components.models.datalayer.AssetData) Resource(org.apache.sling.api.resource.Resource) PageData(com.adobe.cq.wcm.core.components.models.datalayer.PageData) EMPTY_SUPPLIER(com.adobe.cq.wcm.core.components.models.datalayer.builder.DataLayerSupplier.EMPTY_SUPPLIER) HashMap(java.util.HashMap) ComponentData(com.adobe.cq.wcm.core.components.models.datalayer.ComponentData) StringUtils(org.apache.commons.lang3.StringUtils) DamConstants(com.day.cq.dam.api.DamConstants) DataLayerSupplierImpl(com.adobe.cq.wcm.core.components.internal.models.v1.datalayer.builder.DataLayerSupplierImpl) TagConstants(com.day.cq.tagging.TagConstants) Calendar(java.util.Calendar) Stream(java.util.stream.Stream) Map(java.util.Map) Optional(java.util.Optional) ContainerData(com.adobe.cq.wcm.core.components.models.datalayer.ContainerData) NotNull(org.jetbrains.annotations.NotNull) HashMap(java.util.HashMap) ValueMap(org.apache.sling.api.resource.ValueMap) Calendar(java.util.Calendar) Resource(org.apache.sling.api.resource.Resource) Stream(java.util.stream.Stream) Date(java.util.Date)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)26 HashMap (java.util.HashMap)9 List (java.util.List)9 Map (java.util.Map)9 Optional (java.util.Optional)9 Collectors (java.util.stream.Collectors)8 Set (java.util.Set)7 lombok.val (lombok.val)7 ArrayList (java.util.ArrayList)5 Arrays (java.util.Arrays)5 Stream (java.util.stream.Stream)5 ColumnSpec (com.thinkbiganalytics.util.ColumnSpec)3 IOException (java.io.IOException)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 Slf4j (lombok.extern.slf4j.Slf4j)3 FlowFile (org.apache.nifi.flowfile.FlowFile)3 CollectionUtils (org.apereo.cas.util.CollectionUtils)3 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 ThriftService (com.thinkbiganalytics.nifi.v2.thrift.ThriftService)2