Projekt

Obecné

Profil

« Předchozí | Další » 

Revize ba05f7dc

Přidáno uživatelem Tomáš Šimandl před více než 6 roky(ů)

Modified backend to accept graph and configuration in json format instead of jar files + added filters

Zobrazit rozdíly:

.gitignore
1
sources/.idea/
2
sources/build/
3
sources/WebContent/node_modules/
sources/WebContent/WEB-INF/web.xml
17 17
	</context-param>
18 18
	<context-param>
19 19
		<param-name>DbPsw</param-name>
20
		<param-value></param-value>
20
		<param-value>NULL</param-value>
21 21
	</context-param>
22 22
	<context-param>
23 23
		<param-name>HOME_URL</param-name>
......
26 26
	</context-param>
27 27
	<context-param>
28 28
		<param-name>storageLocation</param-name>
29
		<param-value>C:\Users\adnuk\Documents\aswi\uloziste</param-value>
29
		<param-value>C:\Users\Tomas\Documents\imiger\storage</param-value>
30 30
	</context-param>
31 31
	<context-param>
32
		<param-name>crceApiBase</param-name>
33
		<param-value>http://localhost:8081/rest/v2</param-value>
32
		<param-name>configLocation</param-name>
33
		<param-value>C:\Users\Tomas\Documents\imiger\config</param-value>
34 34
	</context-param>
35 35

  
36 36
	<context-param>
sources/src/cz/zcu/kiv/offscreen/AttributeType.java
1
package cz.zcu.kiv.offscreen;
2

  
3
import cz.zcu.kiv.offscreen.graph.GraphManager;
4

  
5
public class AttributeType {
6
    public String name;
7
    public GraphManager.AttributeDataType dataType;
8
    public String text;
9

  
10
    public AttributeType(String name, GraphManager.AttributeDataType dataType, String text) {
11
        this.name = name;
12
        this.dataType = dataType;
13
        this.text = text;
14
    }
15

  
16
    public String getName() {
17
        return name;
18
    }
19

  
20
    public GraphManager.AttributeDataType getDataType() {
21
        return dataType;
22
    }
23
}
sources/src/cz/zcu/kiv/offscreen/api/EdgeInterface.java
4 4
 */
5 5
package cz.zcu.kiv.offscreen.api;
6 6

  
7
import cz.zcu.kiv.offscreen.graph.SubedgeInfo;
8

  
9
import java.util.List;
10

  
7 11
/**
8 12
 *
9 13
 * @author Jindra Pavlíková <jindra.pav2@seznam.cz>
......
15 19
    public String getTo();
16 20

  
17 21
    public int getId();
22

  
23
    public List<SubedgeInfo> getSubedgeInfo();
24

  
25
    public void setSubedgeInfo(List<SubedgeInfo> subedgeInfo);
18 26
}
sources/src/cz/zcu/kiv/offscreen/api/GraphInterface.java
4 4
 */
5 5
package cz.zcu.kiv.offscreen.api;
6 6

  
7
import cz.zcu.kiv.offscreen.AttributeType;
8
import cz.zcu.kiv.offscreen.graph.EdgeArchetype;
9
import cz.zcu.kiv.offscreen.graph.VertexArchetype;
10

  
7 11
import java.util.List;
8 12
import java.util.Map;
9 13

  
......
17 21
    public void addVertex(String name, VertexInterface vertex);
18 22
    public Map<String, VertexInterface> getVertices();
19 23
    public List<EdgeInterface> getEdges();
20
    
24
    public List<VertexArchetype>  getVertexArchetypes();
25
    public List<EdgeArchetype> getEdgeArchetypes();
26
    public void setVertexArchetypes(List<VertexArchetype> vertexArchetypes);
27
    public void setEdgeArchetypes(List<EdgeArchetype> edgeArchetypes);
28
    public void setAttributeTypes(List<AttributeType> attributeTypes);
29
    public void setPossibleEnumValues(Map<Integer, List<String>> possibleEnumValues);
30
    public List<AttributeType> getAttributeTypes();
31
    public Map<String, List<String>> getPossibleEnumValues();
32
    void setArchetypeIcons(Map<String, String> archetypeIcons);
33
    Map<String, String> getArchetypeIcons();
34
    List<Integer> getDefaultGroupArchetypes();
35
    void setDefaultGroupArchetypes(List<Integer> defaultGroupArchetypes);
21 36
}
sources/src/cz/zcu/kiv/offscreen/api/VertexInterface.java
26 26

  
27 27
	public void setImportedPackages(List<String> importedPackages);
28 28

  
29
	public int getArchetype();
30

  
31
	public void setArchetype(int archetype);
32

  
33
	public void setAttributes(List<String[]> attributes);
34

  
35
	public List<String[]> getAttributes();
29 36
}
sources/src/cz/zcu/kiv/offscreen/data/efpportal/CocaexData.java
1
/**
2
 * 
3
 */
4
package cz.zcu.kiv.offscreen.data.efpportal;
5

  
6
import java.util.HashMap;
7
import java.util.Map;
8

  
9
/**
10
 * 
11
 * Representation of EFPPortal's connections . A connection consists of a provided and required features.
12
 * 
13
 * @author Jiri Loudil
14
 *
15
 */
16
public class CocaexData {
17
	/**
18
	 * Map of all provided features.
19
	 */
20
	private Map<String, CocaexDataFeature> providedFeatures;
21
	
22
	/**
23
	 * Map of all required features.
24
	 */
25
	private Map<String, CocaexDataFeature> requiredFeatures;
26
	
27
	public CocaexData() {
28
		this.providedFeatures = new HashMap<String, CocaexDataFeature>();
29
		this.requiredFeatures = new HashMap<String, CocaexDataFeature>();
30
	}
31

  
32
	/**
33
	 * @return the providedFeatures
34
	 */
35
	public Map<String, CocaexDataFeature> getProvidedFeatures() {
36
		return providedFeatures;
37
	}
38

  
39
	/**
40
	 * @return the importedFeatures
41
	 */
42
	public Map<String, CocaexDataFeature> getRequiredFeatures() {
43
		return requiredFeatures;
44
	}
45

  
46
}
1
///**
2
// *
3
// */
4
//package cz.zcu.kiv.offscreen.data.efpportal;
5
//
6
//import java.util.HashMap;
7
//import java.util.Map;
8
//
9
///**
10
// *
11
// * Representation of EFPPortal's connections . A connection consists of a provided and required features.
12
// *
13
// * @author Jiri Loudil
14
// *
15
// */
16
//public class CocaexData {
17
//	/**
18
//	 * Map of all provided features.
19
//	 */
20
//	private Map<String, CocaexDataFeature> providedFeatures;
21
//
22
//	/**
23
//	 * Map of all required features.
24
//	 */
25
//	private Map<String, CocaexDataFeature> requiredFeatures;
26
//
27
//	public CocaexData() {
28
//		this.providedFeatures = new HashMap<String, CocaexDataFeature>();
29
//		this.requiredFeatures = new HashMap<String, CocaexDataFeature>();
30
//	}
31
//
32
//	/**
33
//	 * @return the providedFeatures
34
//	 */
35
//	public Map<String, CocaexDataFeature> getProvidedFeatures() {
36
//		return providedFeatures;
37
//	}
38
//
39
//	/**
40
//	 * @return the importedFeatures
41
//	 */
42
//	public Map<String, CocaexDataFeature> getRequiredFeatures() {
43
//		return requiredFeatures;
44
//	}
45
//
46
//}
sources/src/cz/zcu/kiv/offscreen/data/efpportal/CocaexDataEfp.java
1
package cz.zcu.kiv.offscreen.data.efpportal;
2

  
3
import cz.zcu.kiv.efps.comparator.result.EfpEvalResult.MatchingResult;
4
import cz.zcu.kiv.efps.types.datatypes.EfpValueType;
5

  
6
/**
7
 * Holds EFP's data.
8
 * 
9
 * @author Jiri Loudil
10
 *
11
 */
12
public class CocaexDataEfp {
13
	private String efpName;
14
	private String efpValueTypeName;
15
	private EfpValueType efpValue;
16
	private MatchingResult typeError;
17
	
18
	/**
19
	 * @return the efpName
20
	 */
21
	public String getEfpName() {
22
		return efpName;
23
	}
24
	/**
25
	 * @param efpName the efpName to set
26
	 */
27
	public void setEfpName(String efpName) {
28
		this.efpName = efpName;
29
	}
30
	/**
31
	 * @return the efpValueTypeName
32
	 */
33
	public String getEfpValueTypeName() {
34
		return efpValueTypeName;
35
	}
36
	/**
37
	 * @param efpValueTypeName the efpValueTypeName to set
38
	 */
39
	public void setEfpValueTypeName(String efpValueTypeName) {
40
		this.efpValueTypeName = efpValueTypeName;
41
	}
42
	/**
43
	 * @return the efpValue
44
	 */
45
	public EfpValueType getEfpValue() {
46
		return efpValue;
47
	}
48
	/**
49
	 * @param efpValue the efpValue to set
50
	 */
51
	public void setEfpValue(EfpValueType efpValue) {
52
		this.efpValue = efpValue;
53
	}
54

  
55
	/**
56
	 * @return the typeError
57
	 */
58
	public MatchingResult getTypeError() {
59
		return typeError;
60
	}
61

  
62
	/**
63
	 * @param typeError the typeError to set
64
	 */
65
	public void setTypeError(MatchingResult typeError) {
66
		this.typeError = typeError;
67
	}
68
	
69
}
1
//package cz.zcu.kiv.offscreen.data.efpportal;
2
//
3
//import cz.zcu.kiv.efps.comparator.result.EfpEvalResult.MatchingResult;
4
//import cz.zcu.kiv.efps.types.datatypes.EfpValueType;
5
//
6
///**
7
// * Holds EFP's data.
8
// *
9
// * @author Jiri Loudil
10
// *
11
// */
12
//public class CocaexDataEfp {
13
//	private String efpName;
14
//	private String efpValueTypeName;
15
//	private EfpValueType efpValue;
16
//	private MatchingResult typeError;
17
//
18
//	/**
19
//	 * @return the efpName
20
//	 */
21
//	public String getEfpName() {
22
//		return efpName;
23
//	}
24
//	/**
25
//	 * @param efpName the efpName to set
26
//	 */
27
//	public void setEfpName(String efpName) {
28
//		this.efpName = efpName;
29
//	}
30
//	/**
31
//	 * @return the efpValueTypeName
32
//	 */
33
//	public String getEfpValueTypeName() {
34
//		return efpValueTypeName;
35
//	}
36
//	/**
37
//	 * @param efpValueTypeName the efpValueTypeName to set
38
//	 */
39
//	public void setEfpValueTypeName(String efpValueTypeName) {
40
//		this.efpValueTypeName = efpValueTypeName;
41
//	}
42
//	/**
43
//	 * @return the efpValue
44
//	 */
45
//	public EfpValueType getEfpValue() {
46
//		return efpValue;
47
//	}
48
//	/**
49
//	 * @param efpValue the efpValue to set
50
//	 */
51
//	public void setEfpValue(EfpValueType efpValue) {
52
//		this.efpValue = efpValue;
53
//	}
54
//
55
//	/**
56
//	 * @return the typeError
57
//	 */
58
//	public MatchingResult getTypeError() {
59
//		return typeError;
60
//	}
61
//
62
//	/**
63
//	 * @param typeError the typeError to set
64
//	 */
65
//	public void setTypeError(MatchingResult typeError) {
66
//		this.typeError = typeError;
67
//	}
68
//
69
//}
sources/src/cz/zcu/kiv/offscreen/data/efpportal/CocaexDataFeature.java
1
package cz.zcu.kiv.offscreen.data.efpportal;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
/**
7
 * Holds feature's data.
8
 * 
9
 * @author Jiri Loudil
10
 *
11
 */
12
public class CocaexDataFeature {
13
	private List<CocaexDataEfp> efps;
14

  
15
	public CocaexDataFeature() {
16
		this.efps = new ArrayList<CocaexDataEfp>();
17
	}
18

  
19
	/**
20
	 * @return the efps
21
	 */
22
	public List<CocaexDataEfp> getEfps() {
23
		return efps;
24
	}
25

  
26
	/**
27
	 * @param efps the efps to set
28
	 */
29
	public void setEfps(List<CocaexDataEfp> efps) {
30
		this.efps = efps;
31
	}
32

  
33
}
1
//package cz.zcu.kiv.offscreen.data.efpportal;
2
//
3
//import java.util.ArrayList;
4
//import java.util.List;
5
//
6
///**
7
// * Holds feature's data.
8
// *
9
// * @author Jiri Loudil
10
// *
11
// */
12
//public class CocaexDataFeature {
13
//	private List<CocaexDataEfp> efps;
14
//
15
//	public CocaexDataFeature() {
16
//		this.efps = new ArrayList<CocaexDataEfp>();
17
//	}
18
//
19
//	/**
20
//	 * @return the efps
21
//	 */
22
//	public List<CocaexDataEfp> getEfps() {
23
//		return efps;
24
//	}
25
//
26
//	/**
27
//	 * @param efps the efps to set
28
//	 */
29
//	public void setEfps(List<CocaexDataEfp> efps) {
30
//		this.efps = efps;
31
//	}
32
//
33
//}
sources/src/cz/zcu/kiv/offscreen/data/efpportal/CocaexWrapper.java
1
package cz.zcu.kiv.offscreen.data.efpportal;
2

  
3
import java.util.Map;
4

  
5
/**
6
 * 
7
 * EFPPortal export data wrapper. Contains mappings for feature connection names and EFPs names.
8
 * 
9
 * @author Jiri Loudil
10
 *
11
 */
12
public class CocaexWrapper {
13
	/**
14
	 * Feature names mapping.
15
	 */
16
	private Map<String, String> featureMappings;
17
	
18
	/**
19
	 * EFPs name s mapping.
20
	 */
21
	private Map<String, String> efpMappings;
22
	
23
	/**
24
	 * EFPPortal data with IDs instead of names for EFPs and Features.
25
	 */
26
	private Map<String, CocaexData> data;
27
	
28
	/**
29
	 * @return the featureMappings
30
	 */
31
	public Map<String, String> getFeatureMappings() {
32
		return featureMappings;
33
	}
34
	/**
35
	 * @param featureMappings the featureMappings to set
36
	 */
37
	public void setFeatureMappings(Map<String, String> featureMappings) {
38
		this.featureMappings = featureMappings;
39
	}
40
	/**
41
	 * @return the efpMappings
42
	 */
43
	public Map<String, String> getEfpMappings() {
44
		return efpMappings;
45
	}
46
	/**
47
	 * @param efpMappings the efpMappings to set
48
	 */
49
	public void setEfpMappings(Map<String, String> efpMappings) {
50
		this.efpMappings = efpMappings;
51
	}
52
	/**
53
	 * @return the data
54
	 */
55
	public Map<String, CocaexData> getData() {
56
		return data;
57
	}
58
	/**
59
	 * @param data the data to set
60
	 */
61
	public void setData(Map<String, CocaexData> data) {
62
		this.data = data;
63
	}
64
	
65
	
66
}
1
//package cz.zcu.kiv.offscreen.data.efpportal;
2
//
3
//import java.util.Map;
4
//
5
///**
6
// *
7
// * EFPPortal export data wrapper. Contains mappings for feature connection names and EFPs names.
8
// *
9
// * @author Jiri Loudil
10
// *
11
// */
12
//public class CocaexWrapper {
13
//	/**
14
//	 * Feature names mapping.
15
//	 */
16
//	private Map<String, String> featureMappings;
17
//
18
//	/**
19
//	 * EFPs name s mapping.
20
//	 */
21
//	private Map<String, String> efpMappings;
22
//
23
//	/**
24
//	 * EFPPortal data with IDs instead of names for EFPs and Features.
25
//	 */
26
//	private Map<String, CocaexData> data;
27
//
28
//	/**
29
//	 * @return the featureMappings
30
//	 */
31
//	public Map<String, String> getFeatureMappings() {
32
//		return featureMappings;
33
//	}
34
//	/**
35
//	 * @param featureMappings the featureMappings to set
36
//	 */
37
//	public void setFeatureMappings(Map<String, String> featureMappings) {
38
//		this.featureMappings = featureMappings;
39
//	}
40
//	/**
41
//	 * @return the efpMappings
42
//	 */
43
//	public Map<String, String> getEfpMappings() {
44
//		return efpMappings;
45
//	}
46
//	/**
47
//	 * @param efpMappings the efpMappings to set
48
//	 */
49
//	public void setEfpMappings(Map<String, String> efpMappings) {
50
//		this.efpMappings = efpMappings;
51
//	}
52
//	/**
53
//	 * @return the data
54
//	 */
55
//	public Map<String, CocaexData> getData() {
56
//		return data;
57
//	}
58
//	/**
59
//	 * @param data the data to set
60
//	 */
61
//	public void setData(Map<String, CocaexData> data) {
62
//		this.data = data;
63
//	}
64
//
65
//
66
//}
sources/src/cz/zcu/kiv/offscreen/efp/utils/JsonTransformer.java
1
package cz.zcu.kiv.offscreen.efp.utils;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.IOException;
5
import java.util.zip.GZIPInputStream;
6

  
7
import javax.servlet.http.HttpServletRequest;
8

  
9
import org.apache.log4j.Logger;
10

  
11
import net.sf.json.JSONObject;
12

  
13
import org.apache.commons.codec.binary.Base64;
14
import org.apache.commons.io.IOUtils;
15

  
16
import com.google.gson.Gson;
17
import com.google.gson.GsonBuilder;
18

  
19
import cz.zcu.kiv.efps.types.datatypes.EfpValueType;
20
import cz.zcu.kiv.efps.types.serialisation.json.EfpValueTypeAdapter;
21
import cz.zcu.kiv.offscreen.api.GraphInterface;
22
import cz.zcu.kiv.offscreen.data.efpportal.CocaexWrapper;
23
import cz.zcu.kiv.offscreen.graph.GraphExport;
24
import cz.zcu.kiv.offscreen.graph.creator.EfpGraphTransfomer;
25

  
26
/**
27
 * 
28
 * Transofma and decompress tools for incoming JSON.
29
 * 
30
 * @author Jiri Loudil
31
 *
32
 */
33
public class JsonTransformer {
34
	private Logger logger = Logger.getLogger(JsonTransformer.class);
35

  
36
	/**
37
	 * 
38
	 * Deserialize input JSON and transform to graph JSON.
39
	 * 
40
	 * @param inputJSON
41
	 * @param request
42
	 * @return
43
	 * @throws IOException
44
	 */
45
	public String transformInputJSONToGraphJSON(String inputJSON,
46
			HttpServletRequest request) throws IOException {
47
		CocaexWrapper efpResults;
48

  
49
		GsonBuilder gsonBuilder = new GsonBuilder();
50
		// JSON deserializing adapter provided for EFP type classes
51
		gsonBuilder.registerTypeAdapter(EfpValueType.class,
52
				new EfpValueTypeAdapter());
53
		// JSON deserializing adapter for the Wrapper class
54
		gsonBuilder.registerTypeAdapter(CocaexWrapper.class,
55
				new WrapperDeserializer());
56
		Gson gson = gsonBuilder.create();
57

  
58
		// decode + unzip received data
59
		String data = decompress(inputJSON);
60

  
61
		// deserialize using deserializer adapters
62
		efpResults = gson.fromJson(data, CocaexWrapper.class);
63

  
64
		request.setAttribute("efpPortalEfpNames", efpResults.getEfpMappings());
65

  
66
		// transform received data to readable graph form
67
		EfpGraphTransfomer transformer = new EfpGraphTransfomer(efpResults);
68
		GraphInterface graph = transformer.transform();
69
		GraphExport export = new GraphExport(graph);
70

  
71
		// transform graph to JSON
72
		JSONObject o = JSONObject.fromObject(export);
73

  
74
		return o.toString();
75
	}
76

  
77
	/**
78
	 * Decode and unzip a Base64 encoded GZIPed string.
79
	 * 
80
	 * @param input
81
	 * @return
82
	 * @throws IOException
83
	 */
84
	private String decompress(String input) throws IOException {
85
		logger.trace("ENTRY");
86
		String result = null;
87

  
88
		byte[] bytes = Base64.decodeBase64(input);
89
		GZIPInputStream zi = null;
90
		try {
91
			zi = new GZIPInputStream(new ByteArrayInputStream(bytes));
92
			result = IOUtils.toString(zi);
93
		} finally {
94
			IOUtils.closeQuietly(zi);
95
		}
96
		logger.trace("EXIT");
97

  
98
		return result;
99
	}
100

  
101
}
1
//package cz.zcu.kiv.offscreen.efp.utils;
2
//
3
//import java.io.ByteArrayInputStream;
4
//import java.io.IOException;
5
//import java.util.zip.GZIPInputStream;
6
//
7
//import javax.servlet.http.HttpServletRequest;
8
//
9
//import org.apache.log4j.Logger;
10
//
11
//import net.sf.json.JSONObject;
12
//
13
//import org.apache.commons.codec.binary.Base64;
14
//import org.apache.commons.io.IOUtils;
15
//
16
//import com.google.gson.Gson;
17
//import com.google.gson.GsonBuilder;
18
//
19
//import cz.zcu.kiv.efps.types.datatypes.EfpValueType;
20
//import cz.zcu.kiv.efps.types.serialisation.json.EfpValueTypeAdapter;
21
//import cz.zcu.kiv.offscreen.api.GraphInterface;
22
//import cz.zcu.kiv.offscreen.data.efpportal.CocaexWrapper;
23
//import cz.zcu.kiv.offscreen.graph.GraphExport;
24
//import cz.zcu.kiv.offscreen.graph.creator.EfpGraphTransfomer;
25
//
26
///**
27
// *
28
// * Transofma and decompress tools for incoming JSON.
29
// *
30
// * @author Jiri Loudil
31
// *
32
// */
33
//public class JsonTransformer {
34
//	private Logger logger = Logger.getLogger(JsonTransformer.class);
35
//
36
//	/**
37
//	 *
38
//	 * Deserialize input JSON and transform to graph JSON.
39
//	 *
40
//	 * @param inputJSON
41
//	 * @param request
42
//	 * @return
43
//	 * @throws IOException
44
//	 */
45
//	public String transformInputJSONToGraphJSON(String inputJSON,
46
//			HttpServletRequest request) throws IOException {
47
//		CocaexWrapper efpResults;
48
//
49
//		GsonBuilder gsonBuilder = new GsonBuilder();
50
//		// JSON deserializing adapter provided for EFP type classes
51
//		gsonBuilder.registerTypeAdapter(EfpValueType.class,
52
//				new EfpValueTypeAdapter());
53
//		// JSON deserializing adapter for the Wrapper class
54
//		gsonBuilder.registerTypeAdapter(CocaexWrapper.class,
55
//				new WrapperDeserializer());
56
//		Gson gson = gsonBuilder.create();
57
//
58
//		// decode + unzip received data
59
//		String data = decompress(inputJSON);
60
//
61
//		// deserialize using deserializer adapters
62
//		efpResults = gson.fromJson(data, CocaexWrapper.class);
63
//
64
//		request.setAttribute("efpPortalEfpNames", efpResults.getEfpMappings());
65
//
66
//		// transform received data to readable graph form
67
//		EfpGraphTransfomer transformer = new EfpGraphTransfomer(efpResults);
68
//		GraphInterface graph = transformer.transform();
69
//		GraphExport export = new GraphExport(graph);
70
//
71
//		// transform graph to JSON
72
//		JSONObject o = JSONObject.fromObject(export);
73
//
74
//		return o.toString();
75
//	}
76
//
77
//	/**
78
//	 * Decode and unzip a Base64 encoded GZIPed string.
79
//	 *
80
//	 * @param input
81
//	 * @return
82
//	 * @throws IOException
83
//	 */
84
//	private String decompress(String input) throws IOException {
85
//		logger.trace("ENTRY");
86
//		String result = null;
87
//
88
//		byte[] bytes = Base64.decodeBase64(input);
89
//		GZIPInputStream zi = null;
90
//		try {
91
//			zi = new GZIPInputStream(new ByteArrayInputStream(bytes));
92
//			result = IOUtils.toString(zi);
93
//		} finally {
94
//			IOUtils.closeQuietly(zi);
95
//		}
96
//		logger.trace("EXIT");
97
//
98
//		return result;
99
//	}
100
//
101
//}
sources/src/cz/zcu/kiv/offscreen/efp/utils/WrapperDeserializer.java
1
package cz.zcu.kiv.offscreen.efp.utils;
2

  
3
import java.lang.reflect.Type;
4
import java.util.HashMap;
5
import java.util.Map;
6

  
7
import org.apache.log4j.Logger;
8

  
9
import com.google.gson.Gson;
10
import com.google.gson.GsonBuilder;
11
import com.google.gson.JsonDeserializationContext;
12
import com.google.gson.JsonDeserializer;
13
import com.google.gson.JsonElement;
14
import com.google.gson.JsonObject;
15

  
16
import cz.zcu.kiv.efps.types.datatypes.EfpValueType;
17
import cz.zcu.kiv.efps.types.serialisation.json.EfpValueTypeAdapter;
18
import cz.zcu.kiv.offscreen.data.efpportal.CocaexData;
19
import cz.zcu.kiv.offscreen.data.efpportal.CocaexWrapper;
20

  
21
/**
22
 * 
23
 * CocaexWrapper class deserializer.
24
 * 
25
 * @author Jiri Loudil
26
 * 
27
 */
28
public class WrapperDeserializer implements JsonDeserializer<CocaexWrapper> {
29
	private Logger logger = Logger.getLogger(WrapperDeserializer.class);
30

  
31
	@Override
32
	public CocaexWrapper deserialize(JsonElement json, Type typeOfT,
33
			JsonDeserializationContext context) {
34
		logger.trace("ENTRY");
35

  
36
		GsonBuilder gsonBuilder = new GsonBuilder();
37
		// JSON deserializing adapter provided for EFP type classes
38
		gsonBuilder.registerTypeAdapter(EfpValueType.class,
39
				new EfpValueTypeAdapter());
40
		Gson gson = gsonBuilder.create();
41

  
42
		CocaexWrapper wrapper = gson.fromJson(json, CocaexWrapper.class);
43
		JsonObject jo = json.getAsJsonObject();
44

  
45
		Map<String, String> featureMappings = new HashMap<String, String>();
46
		Map<String, String> efpMappings = new HashMap<String, String>();
47
		Map<String, CocaexData> data = new HashMap<String, CocaexData>();
48

  
49
		// parse feature mappings
50
		JsonObject featuresObject = jo.getAsJsonObject("featureMappings");
51
		for (Map.Entry<String, JsonElement> entry : featuresObject.entrySet()) {
52
			featureMappings.put(entry.getKey(), entry.getValue().getAsString());
53
		}
54

  
55
		// parse efps mappings
56
		JsonObject efpsObject = jo.getAsJsonObject("efpMappings");
57
		for (Map.Entry<String, JsonElement> entry : efpsObject.entrySet()) {
58
			efpMappings.put(entry.getKey(), entry.getValue().getAsString());
59
		}
60

  
61
		// parse data
62
		JsonObject dataObject = jo.getAsJsonObject("data");
63
		for (Map.Entry<String, JsonElement> entry : dataObject.entrySet()) {
64
			data.put(entry.getKey(), (CocaexData) context.deserialize(
65
					entry.getValue(), CocaexData.class));
66
		}
67

  
68
		// fill output structure
69
		wrapper.setFeatureMappings(featureMappings);
70
		wrapper.setEfpMappings(efpMappings);
71
		wrapper.setData(data);
72
		logger.trace("EXIT");
73

  
74
		return wrapper;
75
	}
76
}
1
//package cz.zcu.kiv.offscreen.efp.utils;
2
//
3
//import java.lang.reflect.Type;
4
//import java.util.HashMap;
5
//import java.util.Map;
6
//
7
//import org.apache.log4j.Logger;
8
//
9
//import com.google.gson.Gson;
10
//import com.google.gson.GsonBuilder;
11
//import com.google.gson.JsonDeserializationContext;
12
//import com.google.gson.JsonDeserializer;
13
//import com.google.gson.JsonElement;
14
//import com.google.gson.JsonObject;
15
//
16
//import cz.zcu.kiv.efps.types.datatypes.EfpValueType;
17
//import cz.zcu.kiv.efps.types.serialisation.json.EfpValueTypeAdapter;
18
//import cz.zcu.kiv.offscreen.data.efpportal.CocaexData;
19
//import cz.zcu.kiv.offscreen.data.efpportal.CocaexWrapper;
20
//
21
///**
22
// *
23
// * CocaexWrapper class deserializer.
24
// *
25
// * @author Jiri Loudil
26
// *
27
// */
28
//public class WrapperDeserializer implements JsonDeserializer<CocaexWrapper> {
29
//	private Logger logger = Logger.getLogger(WrapperDeserializer.class);
30
//
31
//	@Override
32
//	public CocaexWrapper deserialize(JsonElement json, Type typeOfT,
33
//			JsonDeserializationContext context) {
34
//		logger.trace("ENTRY");
35
//
36
//		GsonBuilder gsonBuilder = new GsonBuilder();
37
//		// JSON deserializing adapter provided for EFP type classes
38
//		gsonBuilder.registerTypeAdapter(EfpValueType.class,
39
//				new EfpValueTypeAdapter());
40
//		Gson gson = gsonBuilder.create();
41
//
42
//		CocaexWrapper wrapper = gson.fromJson(json, CocaexWrapper.class);
43
//		JsonObject jo = json.getAsJsonObject();
44
//
45
//		Map<String, String> featureMappings = new HashMap<String, String>();
46
//		Map<String, String> efpMappings = new HashMap<String, String>();
47
//		Map<String, CocaexData> data = new HashMap<String, CocaexData>();
48
//
49
//		// parse feature mappings
50
//		JsonObject featuresObject = jo.getAsJsonObject("featureMappings");
51
//		for (Map.Entry<String, JsonElement> entry : featuresObject.entrySet()) {
52
//			featureMappings.put(entry.getKey(), entry.getValue().getAsString());
53
//		}
54
//
55
//		// parse efps mappings
56
//		JsonObject efpsObject = jo.getAsJsonObject("efpMappings");
57
//		for (Map.Entry<String, JsonElement> entry : efpsObject.entrySet()) {
58
//			efpMappings.put(entry.getKey(), entry.getValue().getAsString());
59
//		}
60
//
61
//		// parse data
62
//		JsonObject dataObject = jo.getAsJsonObject("data");
63
//		for (Map.Entry<String, JsonElement> entry : dataObject.entrySet()) {
64
//			data.put(entry.getKey(), (CocaexData) context.deserialize(
65
//					entry.getValue(), CocaexData.class));
66
//		}
67
//
68
//		// fill output structure
69
//		wrapper.setFeatureMappings(featureMappings);
70
//		wrapper.setEfpMappings(efpMappings);
71
//		wrapper.setData(data);
72
//		logger.trace("EXIT");
73
//
74
//		return wrapper;
75
//	}
76
//}
sources/src/cz/zcu/kiv/offscreen/graph/Attribute.java
1
package cz.zcu.kiv.offscreen.graph;
2

  
3
public class Attribute {
4
    int typeIndex;
5
    Object value;
6

  
7
    public Attribute(int typeIndex, Object value) {
8
        this.typeIndex = typeIndex;
9
        this.value = value;
10
    }
11
}
sources/src/cz/zcu/kiv/offscreen/graph/EdgeArchetype.java
1
package cz.zcu.kiv.offscreen.graph;
2

  
3
public class EdgeArchetype {
4
    public String name;
5
    public String text;
6

  
7
    EdgeArchetype(String name, String text) {
8
        this.name = name;
9
        this.text = text;
10
    }
11

  
12
    public String getName() {
13
        return  name;
14
    }
15
}
sources/src/cz/zcu/kiv/offscreen/graph/EdgeArchetypeInfo.java
1
package cz.zcu.kiv.offscreen.graph;
2

  
3
public class EdgeArchetypeInfo {
4
    /**
5
     * index of the archetype of the vertex the edge leads to
6
     */
7
    public int fromArchetypeIndex;
8

  
9
    /**
10
     * index of the archetype of the edge
11
     */
12
    public int edgeArchetypeIndex;
13

  
14
    /**
15
     * index of the archetype of the vertex the edge leads from
16
     */
17
    public int toArchetypeIndex;
18

  
19
    public EdgeArchetypeInfo(int fromArchetypeIndex, int edgeArchetypeIndex, int toArchetypeIndex) {
20
        this.fromArchetypeIndex = fromArchetypeIndex;
21
        this.edgeArchetypeIndex = edgeArchetypeIndex;
22
        this.toArchetypeIndex = toArchetypeIndex;
23
    }
24

  
25
    @Override
26
    public int hashCode() {
27
        return fromArchetypeIndex * 10000 + edgeArchetypeIndex * 100 + fromArchetypeIndex;
28
    }
29

  
30
    @Override
31
    public boolean equals(Object obj) {
32
        EdgeArchetypeInfo info = (EdgeArchetypeInfo)obj;
33
        return (info.fromArchetypeIndex == fromArchetypeIndex) && (info.edgeArchetypeIndex == edgeArchetypeIndex) && (info.toArchetypeIndex == toArchetypeIndex);
34
    }
35
}
sources/src/cz/zcu/kiv/offscreen/graph/EdgeData.java
1
package cz.zcu.kiv.offscreen.graph;
2

  
3
import java.util.*;
4

  
5
public class EdgeData {
6
    public int id;
7
    public int from;
8
    public int to;
9
    public String text;
10
    public int archetypeIndex;
11
    public Map<Integer, Attribute> attributes = new HashMap<>();
12

  
13
    public EdgeData(int id, int from, int to, String text, int archetypeIndex) {
14
        this.id = id;
15
        this.from = from;
16
        this.to = to;
17
        this.text = text;
18
        this.archetypeIndex = archetypeIndex;
19
    }
20

  
21
    public void addAttribute(int attrTypeIndex, Object value) {
22
        Attribute attr = new Attribute(attrTypeIndex, value);
23
        attributes.put(attrTypeIndex, attr);
24
    }
25

  
26
    public void addAttributes(Map<Integer, Attribute> attributes) {
27
        this.attributes.putAll(attributes);
28
    }
29

  
30
    public Attribute getAttribute(int attrTypeIndex) {
31
        return attributes.get(attrTypeIndex);
32
    }
33

  
34
    @Override
35
    public int hashCode() {
36
        return from * 100000 + to;
37
    }
38

  
39
    @Override
40
    public boolean equals(Object edge) {
41
        return from == ((EdgeData) edge).from && to == ((EdgeData) edge).to;
42
    }
43

  
44
    public List<Attribute> getSortedAttributes() {
45
        List<Attribute> list = new ArrayList<>();
46
        ArrayList<Integer> indices = new ArrayList<>(attributes.keySet());
47
        //indices.sort(Integer::compareTo);
48
        Collections.sort(indices); // TODO check correct order
49
        for (int i = 0; i < indices.size(); i++) {
50
            list.add(attributes.get(indices.get(i)));
51
        }
52
        return list;
53
    }
54
}
sources/src/cz/zcu/kiv/offscreen/graph/EdgeEfp.java
1 1
package cz.zcu.kiv.offscreen.graph;
2 2

  
3 3
import java.util.ArrayList;
4
import java.util.List;
4 5

  
5 6
import org.apache.log4j.Logger;
6 7

  
......
65 66
		return edgeId;
66 67
	}
67 68

  
69
	@Override
70
	public List<SubedgeInfo> getSubedgeInfo() {
71
		return null;
72
	}
73

  
74
	@Override
75
	public void setSubedgeInfo(List<SubedgeInfo> subedgeInfo) {
76
		// TODO 30.7.2018 empty body (copy from CoCaEx ASWI)
77
	}
78

  
68 79
	public ArrayList<EfpFeature> getFeatures() {
69 80
		return features;
70 81
	}
sources/src/cz/zcu/kiv/offscreen/graph/EdgeImpl.java
17 17
    private String to;
18 18
    private List<String> packageConnections;
19 19
    private boolean isCompatible;
20
    private List<SubedgeInfo> subedgeInfo;
20 21
    private String compInfoJSON;
21 22
    private Logger logger = Logger.getLogger(EdgeImpl.class);
22 23

  
......
60 61
        return edgeId;
61 62
    }
62 63

  
64
    @Override
65
    public List<SubedgeInfo> getSubedgeInfo() {
66
        return subedgeInfo;
67
    }
68

  
69
    @Override
70
    public void setSubedgeInfo(List<SubedgeInfo> subedgeInfo) {
71
        this.subedgeInfo = subedgeInfo;
72
    }
73

  
74
    @Override
75
    public boolean equals(Object edge) {
76
        if (!(edge instanceof EdgeImpl)) return false;
77
        EdgeImpl cmpEdge = (EdgeImpl) edge;
78
        return from.equals(cmpEdge.from) && to.equals(cmpEdge.to);
79
    }
80

  
63 81
    public List<String> getPackageConnections() {
64 82
        logger.trace("ENTRY");
65 83
        logger.trace("EXIT");
66 84
        return this.packageConnections;
67 85
    }
68 86

  
69
    public void setPackageConnection(List<String> packageConnections) {
87
    public void setPackageConnections(List<String> packageConnections) {
70 88
        logger.trace("ENTRY");
71 89
        this.packageConnections = packageConnections;
72 90
        logger.trace("EXIT");
sources/src/cz/zcu/kiv/offscreen/graph/GraphExport.java
1 1
package cz.zcu.kiv.offscreen.graph;
2 2

  
3
import cz.zcu.kiv.offscreen.AttributeType;
3 4
import cz.zcu.kiv.offscreen.api.EdgeInterface;
4 5
import cz.zcu.kiv.offscreen.api.GraphInterface;
5 6
import cz.zcu.kiv.offscreen.api.VertexInterface;
6 7
import java.util.ArrayList;
7 8
import java.util.List;
9
import java.util.Map;
10

  
8 11
import org.apache.log4j.Logger;
9 12

  
10 13
/*
......
19 22

  
20 23
    private List<VertexInterface> vertices;
21 24
    private List<EdgeInterface> edges;
25
    private List<VertexArchetype> vertexArchetypes;
26
    private List<EdgeArchetype> edgeArchetypes;
27
    private List<AttributeType> attributeTypes;
28
    private Map<String, List<String>> possibleEnumValues;
29
    private Map<String, String> archetypeIcons;
30
    private List<Integer> defaultGroupArchetypes;
31

  
22 32
    private Logger logger = Logger.getLogger(GraphExport.class);
23 33

  
24 34
    public GraphExport(GraphInterface graph) {
25 35
        logger.trace("ENTRY");
26 36
        this.vertices = new ArrayList<VertexInterface>(graph.getVertices().values());
27 37
        this.edges = new ArrayList<EdgeInterface>(graph.getEdges());
38
        this.vertexArchetypes = new ArrayList<VertexArchetype>(graph.getVertexArchetypes());
39
        this.edgeArchetypes = new ArrayList<EdgeArchetype>(graph.getEdgeArchetypes());
40
        this.attributeTypes = new ArrayList<>(graph.getAttributeTypes());
41
        this.possibleEnumValues = graph.getPossibleEnumValues();
42
        this.archetypeIcons = graph.getArchetypeIcons();
43
        this.defaultGroupArchetypes = graph.getDefaultGroupArchetypes();
28 44
        logger.trace("EXIT");
29 45
    }
30 46

  
......
39 55
        logger.trace("EXIT");
40 56
        return vertices;
41 57
    }
58

  
59
    public List<VertexArchetype> getVertexArchetypes() {
60
        return vertexArchetypes;
61
    }
62

  
63
    public List<EdgeArchetype> getEdgeArchetypes() {
64
        return edgeArchetypes;
65
    }
66

  
67
    public List<AttributeType> getAttributeTypes() {
68
        return attributeTypes;
69
    }
70

  
71
    public Map<String, List<String>> getPossibleEnumValues() {
72
        return possibleEnumValues;
73
    }
74

  
75
    public Map<String, String> getArchetypeIcons() {
76
        return archetypeIcons;
77
    }
78

  
79
    public List<Integer> getDefaultGroupArchetypes() {
80
        return defaultGroupArchetypes;
81
    }
42 82
}
sources/src/cz/zcu/kiv/offscreen/graph/GraphImpl.java
1 1
package cz.zcu.kiv.offscreen.graph;
2 2

  
3
import cz.zcu.kiv.offscreen.AttributeType;
3 4
import cz.zcu.kiv.offscreen.api.EdgeInterface;
4 5
import cz.zcu.kiv.offscreen.api.GraphInterface;
5 6
import cz.zcu.kiv.offscreen.api.VertexInterface;
......
18 19
    private Map<String, VertexInterface> vertices;
19 20
    private List<EdgeInterface> edges;
20 21
    private Logger logger = Logger.getLogger(GraphImpl.class);
22
    private List<VertexArchetype> vertexArchetypes;
23
    private List<EdgeArchetype> edgeArchetypes;
24
    private List<AttributeType> attributeTypes;
25
    private Map<String, List<String>> possibleEnumValues;
26
    private List<Integer> defaultGroupArchetypes;
27

  
28
    private Map<String, String> archetypeIcons;
21 29

  
22 30
    public GraphImpl() {
23 31
        logger.trace("ENTRY");
......
33 41
        return edges;
34 42
    }
35 43

  
44
    @Override
45
    public List<VertexArchetype> getVertexArchetypes() {
46
        return vertexArchetypes;
47
    }
48

  
49
    @Override
50
    public List<EdgeArchetype> getEdgeArchetypes() {
51
        return edgeArchetypes;
52
    }
53

  
54
    @Override
55
    public void setVertexArchetypes(List<VertexArchetype> vertexArchetypes) {
56
        this.vertexArchetypes = vertexArchetypes;
57
    }
58

  
59
    @Override
60
    public  void setEdgeArchetypes(List<EdgeArchetype> edgeArchetypes) {
61
        this.edgeArchetypes = edgeArchetypes;
62
    }
63

  
64
    @Override
65
    public void setAttributeTypes(List<AttributeType> attributeTypes) {
66
        this.attributeTypes = attributeTypes;
67
    }
68

  
69
    @Override
70
    public void setPossibleEnumValues(Map<Integer, List<String>> possibleEnumValues) {
71
        this.possibleEnumValues = new HashMap<>();
72
        for (Integer index : possibleEnumValues.keySet()) {
73
            this.possibleEnumValues.put("" + index, possibleEnumValues.get(index));
74
        }
75
    }
76

  
77
    public void setArchetypeIcons(Map<String, String> archetypeIcons) {
78
        this.archetypeIcons = archetypeIcons;
79
    }
80

  
81
    @Override
82
    public List<Integer> getDefaultGroupArchetypes() {
83
        return defaultGroupArchetypes;
84
    }
85

  
86
    @Override
87
    public void setDefaultGroupArchetypes(List<Integer> defaultGroupArchetypes) {
88
        this.defaultGroupArchetypes = defaultGroupArchetypes;
89
    }
90

  
91
    @Override
92
    public List<AttributeType> getAttributeTypes() {
93
        return attributeTypes;
94
    }
95

  
96
    @Override
97
    public Map<String, List<String>> getPossibleEnumValues() {
98
        return possibleEnumValues;
99
    }
100

  
101
    @Override
102
    public Map<String, String> getArchetypeIcons() {
103
        return archetypeIcons;
104
    }
105

  
36 106
    @Override
37 107
    public Map<String, VertexInterface> getVertices() {
38 108
        logger.trace("ENTRY");
sources/src/cz/zcu/kiv/offscreen/graph/GraphManager.java
1
package cz.zcu.kiv.offscreen.graph;
2

  
3
import cz.zcu.kiv.offscreen.AttributeType;
4
import cz.zcu.kiv.offscreen.api.GraphInterface;
5
import cz.zcu.kiv.offscreen.api.VertexInterface;
6
import cz.zcu.kiv.offscreen.graph.filter.*;
7
import cz.zcu.kiv.offscreen.graph.loader.JSONConfigLoader;
8

  
9
import java.util.*;
10

  
11
public class GraphManager {
12

  
13
    public enum AttributeDataType {
14
        NUMBER {
15
            @Override
16
            public String toString() {
17
                return "number";
18
            }
19
        },
20
        DATE {
21
            @Override
22
            public String toString() {
23
                return "date";
24
            }
25
        },
26
        ENUM {
27
            @Override
28
            public String toString() {
29
                return "enum";
30
            }
31
        },
32
        STRING {
33
            @Override
34
            public String toString() {
35
                return "string";
36
            }
37
        }
38
    }
39

  
40
    public List<VertexArchetype> vertexArchetypes = new ArrayList<>();
41
    public List<EdgeArchetype> edgeArchetypes = new ArrayList<>();
42
    public List<AttributeType> attributeTypes = new ArrayList<>();
43

  
44
    /**
45
     * the key is the attributeType index, the value is the list of possible values
46
     */
47
    private Map<Integer, List<String>> possibleEnumValues = new HashMap<>();
48

  
49
    /**
50
     * key is the archetype index, value is the set of vertices of the given archetype
51
     */
52
    public Map<Integer, HashSet<VertexData>> vertices = new HashMap<>();
53

  
54
    /**
55
     * key is the triplet of archetypes {fromVertex, edge, toVertex}, value is the list of edges for the given archetype triplet
56
     */
57
    public Map<EdgeArchetypeInfo, List<EdgeData>> edges = new HashMap<>();
58

  
59
    public void addVertexArchetype(String name, String text) {
60
        vertexArchetypes.add(new VertexArchetype(name, text));
61
    }
62

  
63
    public void addEdgeArchetype(String name, String text) {
64
        edgeArchetypes.add(new EdgeArchetype(name, text));
65
    }
66

  
67
    /**
68
     *
69
     * @param name
70
     * @param dataType
71
     * @param text
72
     */
73
    public void addAttributeType(String name, AttributeDataType dataType, String text) {
74
        attributeTypes.add(new AttributeType(name, dataType, text));
75
    }
76

  
77
    /**
78
     * Adds a list of values to the possible values hashmap. All duplicated are
79
     * removed.
80
     *
81
     * @param attributeTypeId - Id of attribute type
82
     * @param values          - List of values of the corresponding attribute type
83
     */
84
    public void addUniquePossibleAttributeValues(int attributeTypeId, List<String> values) {
85
        if (possibleEnumValues.containsKey(attributeTypeId)) {
86
            List<String> attrValues = possibleEnumValues.get(attributeTypeId);
87
            List<String> valuesWithoutDuplicates = new ArrayList<>(new HashSet<>(values)); // Converting to hashset removes duplicates
88
            valuesWithoutDuplicates.removeAll(attrValues);   // Values to add without values already present in the hashmap
89
            attrValues.addAll(valuesWithoutDuplicates);
90
        } else {
91
            possibleEnumValues.put(attributeTypeId, values);
92
        }
93
    }
94

  
95
    public List<Integer> getEnumPositionsForAttrIndex(int attributeTypeId, List<String> enumValues) {
96
        List<Integer> positions = new ArrayList<>();
97
        if (!possibleEnumValues.containsKey(attributeTypeId)) {
98
            return positions;
99
        }
100

  
101
        List<String> possibleValues = possibleEnumValues.get(attributeTypeId);
102
        for (int i = 0; i < possibleValues.size(); i++) {
103
            String possibleValue = possibleValues.get(i);
104
            if (enumValues.contains(possibleValue)) {
105
                positions.add(i);
106
            }
107
        }
108

  
109
        return positions;
110
    }
111

  
112
    /**
113
     * Gets string values from possible enums for attribute type id.
114
     * @param attributeTypeId - Id of the attribute type
115
     * @param valuePositions - List of positions in the possible enums hashmap for which to find the enum values.
116
     * @return - List of string values of enums.
117
     */
118
    private List<String> getEnumStringsForAttrIndex(int attributeTypeId, List<Integer> valuePositions) {
119
        List<String> values = new ArrayList<>();
120

  
121
        List<String> possibleValues = possibleEnumValues.get(attributeTypeId);
122
        for (int i = 0; i < possibleValues.size(); i++) {
123
            if (valuePositions.contains(i)) {
124
                values.add(possibleValues.get(i));
125
            }
126
        }
127

  
128
        return values;
129
    }
130

  
131
    public AttributeType getAttributeDataTypeByName(String attributeName) {
132
        return attributeTypes.get(getAttributeIndex(attributeName));
133
    }
134

  
135
    /**
136
     * Adds a record to the possibleEnumValues hashset of the attributes possible values.
137
     *
138
     * @param attributeIndex - Index of the attribute for which to add the possible values
139
     * @param possibleValues - All the possible values of the attribute
140
     */
141
    public void addEnumValues(int attributeIndex, List<String> possibleValues) {
142
        possibleEnumValues.put(attributeIndex, possibleValues);
143
    }
144

  
145
    /**
146
     * Creates a new vertex from input parameters and adds it to the map of
147
     * vertices with the archetypeIndex as the key.
148
     *
149
     * @param id             - ID of the vertex to add
150
     * @param title          - Title of the vertex
151
     * @param text           - Text of the vertex
152
     * @param archetypeIndex - Type of archetype associated with this vertex
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff