Search in sources :

Example 26 with Collections

use of java.util.Collections in project arctic-sea by 52North.

the class AbstractCapabilitiesBaseTypeDecoder method parseServiceIdentification.

private OwsServiceIdentification parseServiceIdentification(ServiceIdentification serviceIdentification) {
    if (serviceIdentification == null) {
        return null;
    }
    OwsCode serviceType = parseCode(serviceIdentification.getServiceType());
    Set<String> serviceTypeVersion = Optional.ofNullable(serviceIdentification.getServiceTypeVersionArray()).map(Arrays::stream).orElseGet(Stream::empty).collect(toSet());
    Set<String> fees = Optional.ofNullable(serviceIdentification.getFees()).map(Collections::singleton).orElseGet(Collections::emptySet);
    Set<URI> profiles = Optional.ofNullable(serviceIdentification.getProfileArray()).map(Arrays::stream).orElseGet(Stream::empty).map(URI::create).collect(toSet());
    Set<String> accessConstraints = Optional.ofNullable(serviceIdentification.getAccessConstraintsArray()).map(Arrays::stream).orElseGet(Stream::empty).collect(toSet());
    MultilingualString title = new MultilingualString();
    MultilingualString abstrakt = new MultilingualString();
    Optional.ofNullable(serviceIdentification.getTitleArray()).map(Arrays::stream).orElseGet(Stream::empty).map(this::parseLanguageString).forEach(title::addLocalization);
    Optional.ofNullable(serviceIdentification.getAbstractArray()).map(Arrays::stream).orElseGet(Stream::empty).map(this::parseLanguageString).forEach(abstrakt::addLocalization);
    Set<OwsKeyword> keywords = Optional.ofNullable(serviceIdentification.getKeywordsArray()).map(Arrays::stream).orElseGet(Stream::empty).flatMap(this::parseKeyword).filter(Objects::nonNull).collect(toSet());
    return new OwsServiceIdentification(serviceType, serviceTypeVersion, profiles, fees, accessConstraints, title, abstrakt, keywords);
}
Also used : OwsCode(org.n52.shetland.ogc.ows.OwsCode) LocalizedString(org.n52.janmayen.i18n.LocalizedString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) OwsLanguageString(org.n52.shetland.ogc.ows.OwsLanguageString) OwsServiceIdentification(org.n52.shetland.ogc.ows.OwsServiceIdentification) URI(java.net.URI) OwsKeyword(org.n52.shetland.ogc.ows.OwsKeyword) Stream(java.util.stream.Stream) MultilingualString(org.n52.janmayen.i18n.MultilingualString) Arrays(java.util.Arrays) Collections(java.util.Collections)

Example 27 with Collections

use of java.util.Collections in project engine by Lumeer.

the class SuggestionFacade method keepOnlyMatchingAttributes.

private static List<Collection> keepOnlyMatchingAttributes(List<Collection> collections, String text) {
    for (Collection collection : collections) {
        Set<Attribute> attributes = collection.getAttributes().stream().filter(a -> a.getName().toLowerCase().contains(text)).collect(Collectors.toSet());
        collection.setAttributes(attributes);
    }
    return collections;
}
Also used : View(io.lumeer.api.model.View) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) Set(java.util.Set) SearchQuery(io.lumeer.storage.api.query.SearchQuery) Collectors(java.util.stream.Collectors) LinkType(io.lumeer.api.model.LinkType) SuggestionType(io.lumeer.api.model.SuggestionType) Inject(javax.inject.Inject) List(java.util.List) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) ViewDao(io.lumeer.storage.api.dao.ViewDao) RequestScoped(javax.enterprise.context.RequestScoped) SuggestionQuery(io.lumeer.storage.api.query.SuggestionQuery) Attribute(io.lumeer.api.model.Attribute) JsonSuggestions(io.lumeer.api.dto.JsonSuggestions) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Attribute(io.lumeer.api.model.Attribute) Collection(io.lumeer.api.model.Collection)

Example 28 with Collections

use of java.util.Collections in project engine by Lumeer.

the class CollectionServiceIT method testGetAllCollections.

@Test
public void testGetAllCollections() {
    createCollection(CODE);
    createCollection(CODE2);
    Response response = client.target(COLLECTIONS_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<JsonCollection> collections = response.readEntity(new GenericType<List<JsonCollection>>() {
    });
    assertThat(collections).extracting(Resource::getCode).containsOnly(CODE, CODE2);
    Permissions permissions1 = collections.get(0).getPermissions();
    assertThat(permissions1).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions1).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions1).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
    Permissions permissions2 = collections.get(1).getPermissions();
    assertThat(permissions2).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions2).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions2).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
}
Also used : Response(javax.ws.rs.core.Response) UserDao(io.lumeer.storage.api.dao.UserDao) Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonPermission(io.lumeer.api.dto.JsonPermission) User(io.lumeer.api.model.User) RunWith(org.junit.runner.RunWith) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonCollection(io.lumeer.api.dto.JsonCollection) Resource(io.lumeer.api.model.Resource) JsonPermissions(io.lumeer.api.dto.JsonPermissions) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) MediaType(javax.ws.rs.core.MediaType) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Role(io.lumeer.api.model.Role) JsonAttribute(io.lumeer.api.dto.JsonAttribute) JsonProject(io.lumeer.api.dto.JsonProject) SimplePermission(io.lumeer.core.model.SimplePermission) UriBuilder(javax.ws.rs.core.UriBuilder) Organization(io.lumeer.api.model.Organization) Before(org.junit.Before) Permission(io.lumeer.api.model.Permission) View(io.lumeer.api.model.View) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Permissions(io.lumeer.api.model.Permissions) JsonOrganization(io.lumeer.api.dto.JsonOrganization) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) Project(io.lumeer.api.model.Project) List(java.util.List) Response(javax.ws.rs.core.Response) Attribute(io.lumeer.api.model.Attribute) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Link(javax.ws.rs.core.Link) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) List(java.util.List) JsonCollection(io.lumeer.api.dto.JsonCollection) Test(org.junit.Test)

Example 29 with Collections

use of java.util.Collections in project dspot by STAMP-project.

the class CollectionCreator method generateEmptyCollection.

static CtExpression<?> generateEmptyCollection(CtTypeReference type, String nameMethod, Class<?> typeOfCollection) {
    final Factory factory = type.getFactory();
    final CtType<?> collectionsType = factory.Type().get(Collections.class);
    final CtTypeAccess<?> accessToCollections = factory.createTypeAccess(collectionsType.getReference());
    final CtMethod<?> singletonListMethod = collectionsType.getMethodsByName(nameMethod).get(0);
    final CtExecutableReference<?> executableReference = factory.Core().createExecutableReference();
    executableReference.setStatic(true);
    executableReference.setSimpleName(singletonListMethod.getSimpleName());
    executableReference.setDeclaringType(collectionsType.getReference());
    executableReference.setType(factory.createCtTypeReference(typeOfCollection));
    if (type.getActualTypeArguments().isEmpty()) {
        // supporting Collections.<type>emptyList()
        executableReference.addActualTypeArgument(type);
    } else if (type.getActualTypeArguments().stream().noneMatch(reference -> reference instanceof CtWildcardReference)) {
        // in case type is a list, we copy the Actual arguments
        executableReference.setActualTypeArguments(type.getActualTypeArguments());
    }
    return factory.createInvocation(accessToCollections, executableReference);
}
Also used : CtExecutableReference(spoon.reflect.reference.CtExecutableReference) CtTypeReference(spoon.reflect.reference.CtTypeReference) List(java.util.List) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) CtType(spoon.reflect.declaration.CtType) CtExpression(spoon.reflect.code.CtExpression) CtTypeAccess(spoon.reflect.code.CtTypeAccess) Factory(spoon.reflect.factory.Factory) CtWildcardReference(spoon.reflect.reference.CtWildcardReference) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) CtMethod(spoon.reflect.declaration.CtMethod) CtWildcardReference(spoon.reflect.reference.CtWildcardReference) Factory(spoon.reflect.factory.Factory)

Example 30 with Collections

use of java.util.Collections in project revapi by revapi.

the class Analyzer method gatherConfig.

@SuppressWarnings("unchecked")
private void gatherConfig(AnalysisContext.Builder ctxBld) throws MojoExecutionException {
    if (analysisConfigurationFiles != null && analysisConfigurationFiles.length > 0) {
        for (Object pathOrConfigFile : analysisConfigurationFiles) {
            ConfigurationFile configFile;
            if (pathOrConfigFile instanceof String) {
                configFile = new ConfigurationFile();
                configFile.setPath((String) pathOrConfigFile);
            } else {
                configFile = (ConfigurationFile) pathOrConfigFile;
            }
            String path = configFile.getPath();
            String resource = configFile.getResource();
            if (path == null && resource == null) {
                throw new MojoExecutionException("Either 'path' or 'resource' has to be specified in a configurationFile definition.");
            } else if (path != null && resource != null) {
                throw new MojoExecutionException("Either 'path' or 'resource' has to be specified in a configurationFile definition but" + " not both.");
            }
            String readErrorMessage = "Error while processing the configuration file on " + (path == null ? "classpath " + resource : "path " + path);
            Supplier<Iterator<InputStream>> configFileContents;
            if (path != null) {
                File f = new File(path);
                if (!f.isAbsolute()) {
                    f = new File(project.getBasedir(), path);
                }
                if (!f.isFile() || !f.canRead()) {
                    String message = "Could not locate analysis configuration file '" + f.getAbsolutePath() + "'.";
                    if (failOnMissingConfigurationFiles) {
                        throw new MojoExecutionException(message);
                    } else {
                        log.debug(message);
                        continue;
                    }
                }
                final File ff = f;
                configFileContents = () -> {
                    try {
                        return Collections.<InputStream>singletonList(new FileInputStream(ff)).iterator();
                    } catch (FileNotFoundException e) {
                        throw new MarkerException("Failed to read the configuration file '" + ff.getAbsolutePath() + "'.", e);
                    }
                };
            } else {
                configFileContents = () -> {
                    try {
                        return Collections.list(getClass().getClassLoader().getResources(resource)).stream().map(url -> {
                            try {
                                return url.openStream();
                            } catch (IOException e) {
                                throw new MarkerException("Failed to read the classpath resource '" + url + "'.");
                            }
                        }).iterator();
                    } catch (IOException e) {
                        throw new IllegalArgumentException("Failed to locate classpath resources on path '" + resource + "'.");
                    }
                };
            }
            Iterator<InputStream> it = configFileContents.get();
            List<Integer> nonJsonIndexes = new ArrayList<>(4);
            int idx = 0;
            while (it.hasNext()) {
                ModelNode config;
                try (InputStream in = it.next()) {
                    config = readJson(in);
                } catch (MarkerException | IOException e) {
                    throw new MojoExecutionException(readErrorMessage, e.getCause());
                }
                if (config == null) {
                    nonJsonIndexes.add(idx);
                    continue;
                }
                mergeJsonConfigFile(ctxBld, configFile, config);
                idx++;
            }
            if (!nonJsonIndexes.isEmpty()) {
                idx = 0;
                it = configFileContents.get();
                while (it.hasNext()) {
                    try (Reader rdr = new InputStreamReader(it.next())) {
                        if (nonJsonIndexes.contains(idx)) {
                            mergeXmlConfigFile(ctxBld, configFile, rdr);
                        }
                    } catch (MarkerException | IOException | XmlPullParserException e) {
                        throw new MojoExecutionException(readErrorMessage, e.getCause());
                    }
                    idx++;
                }
            }
        }
    }
    if (analysisConfiguration != null) {
        String text = analysisConfiguration.getValue();
        if (text == null) {
            convertNewStyleConfigFromXml(ctxBld, getRevapi());
        } else {
            ctxBld.mergeConfigurationFromJSON(text);
        }
    }
}
Also used : Arrays(java.util.Arrays) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) XmlToJson(org.revapi.configuration.XmlToJson) MavenProject(org.apache.maven.project.MavenProject) Locale(java.util.Locale) Map(java.util.Map) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) API(org.revapi.API) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Set(java.util.Set) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) Artifact(org.eclipse.aether.artifact.Artifact) AnalysisResult(org.revapi.AnalysisResult) Reader(java.io.Reader) Revapi(org.revapi.Revapi) FileNotFoundException(java.io.FileNotFoundException) ValidationResult(org.revapi.configuration.ValidationResult) List(java.util.List) Stream(java.util.stream.Stream) RepositoryUtils(org.apache.maven.RepositoryUtils) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) ModelNode(org.jboss.dmr.ModelNode) Pattern(java.util.regex.Pattern) Spliterator(java.util.Spliterator) RepositorySystem(org.eclipse.aether.RepositorySystem) Reporter(org.revapi.Reporter) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) Xpp3DomBuilder(org.codehaus.plexus.util.xml.Xpp3DomBuilder) Function(java.util.function.Function) Supplier(java.util.function.Supplier) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Charset(java.nio.charset.Charset) StreamSupport(java.util.stream.StreamSupport) JSONUtil(org.revapi.configuration.JSONUtil) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Iterator(java.util.Iterator) AnalysisContext(org.revapi.AnalysisContext) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Log(org.apache.maven.plugin.logging.Log) InputStreamReader(java.io.InputStreamReader) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) Collectors.toList(java.util.stream.Collectors.toList) RepositoryException(org.eclipse.aether.RepositoryException) Collections(java.util.Collections) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Iterator(java.util.Iterator) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File)

Aggregations

Collections (java.util.Collections)116 List (java.util.List)60 ArrayList (java.util.ArrayList)41 Test (org.junit.Test)39 Map (java.util.Map)38 Collectors (java.util.stream.Collectors)35 Arrays (java.util.Arrays)28 HashMap (java.util.HashMap)27 Set (java.util.Set)25 HashSet (java.util.HashSet)23 IOException (java.io.IOException)19 Collection (java.util.Collection)19 Optional (java.util.Optional)19 TimeUnit (java.util.concurrent.TimeUnit)16 URI (java.net.URI)13 Assert (org.junit.Assert)13 Function (java.util.function.Function)12 Stream (java.util.stream.Stream)12 Before (org.junit.Before)12 Logger (org.slf4j.Logger)12