
org.jclouds.atmos.functions.ParseUserMetadataFromHeaders Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jclouds-shaded Show documentation
Show all versions of jclouds-shaded Show documentation
Provides a shaded jclouds with relocated guava and guice
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.atmos.functions;
import static shaded.com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.atmos.domain.UserMetadata;
import org.jclouds.atmos.reference.AtmosHeaders;
import org.jclouds.http.HttpResponse;
import shaded.com.google.common.base.Function;
import shaded.com.google.common.base.Predicates;
import shaded.com.google.common.base.Splitter;
import shaded.com.google.common.collect.ImmutableMap;
import shaded.com.google.common.collect.ImmutableSet;
import shaded.com.google.common.collect.Maps;
@Singleton
public class ParseUserMetadataFromHeaders implements Function {
private static final Set SYS_KEYS = ImmutableSet.of(
"atime", "ctime", "gid", "itime", "mtime", "nlink",
"parent",
"policyname", "size", "uid", "content-md5", "objectid", "objname", "type");
public UserMetadata apply(HttpResponse from) {
checkNotNull(from, "http response");
Map meta = Maps.filterKeys(
getMetaMap(checkNotNull(from.getFirstHeaderOrNull(AtmosHeaders.META), AtmosHeaders.META)),
Predicates.not(Predicates.in(SYS_KEYS)));
Map listableMeta = (from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META) != null) ? getMetaMap(from
.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META)) : ImmutableMap. of();
Iterable tags = (from.getFirstHeaderOrNull(AtmosHeaders.TAGS) != null) ? Splitter.on(", ").split(
from.getFirstHeaderOrNull(AtmosHeaders.TAGS)) : ImmutableSet. of();
Iterable listableTags = (from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_TAGS) != null) ? Splitter
.on(", ").split(from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_TAGS)) : ImmutableSet. of();
return new UserMetadata(meta, listableMeta, tags, listableTags);
}
private static Map getMetaMap(String meta) {
return Splitter.on(", ").withKeyValueSeparator('=').split(meta);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy