001
014
015 package com.liferay.portal.fabric;
016
017 import com.liferay.portal.fabric.repository.RepositoryHelperUtil;
018 import com.liferay.portal.kernel.process.ProcessCallable;
019 import com.liferay.portal.kernel.util.ObjectGraphUtil.AnnotatedFieldMappingVisitor;
020
021 import java.io.File;
022
023 import java.lang.annotation.Annotation;
024 import java.lang.reflect.Field;
025
026 import java.nio.file.Path;
027
028 import java.util.Collections;
029 import java.util.HashMap;
030 import java.util.Map;
031
032
035 public class FabricResourceMappingVisitor extends AnnotatedFieldMappingVisitor {
036
037 public FabricResourceMappingVisitor(
038 Class<? extends Annotation> annotationClass,
039 Path remoteRepositoryPath) {
040
041 super(
042 Collections.<Class<?>>singleton(ProcessCallable.class),
043 Collections.<Class<? extends Annotation>>singleton(annotationClass),
044 Collections.<Class<?>>singleton(File.class));
045
046 _remoteRepositoryPath = remoteRepositoryPath;
047 }
048
049 public Map<Path, Path> getResourceMap() {
050 return _resourceMap;
051 }
052
053 @Override
054 protected Object doMap(Field field, Object value) {
055 File file = (File)value;
056
057 Path path = file.toPath();
058
059 Path mappedPath = RepositoryHelperUtil.getRepositoryFilePath(
060 _remoteRepositoryPath, path);
061
062 mappedPath = mappedPath.toAbsolutePath();
063
064 _resourceMap.put(path.toAbsolutePath(), mappedPath);
065
066 return mappedPath.toFile();
067 }
068
069 private final Path _remoteRepositoryPath;
070 private final Map<Path, Path> _resourceMap = new HashMap<Path, Path>();
071
072 }