package dk.aau.cs.qweb.airbase.types;

import java.util.ArrayList;
import java.util.List;

import dk.aau.cs.qweb.airbase.Config;

public class TripleContainer {

	private Tuple tuple;

	public TripleContainer(Tuple tuple) {
		this.tuple = tuple;
		List<Quad> informationTriples = new ArrayList<Quad>();
		List<Quad> metadataTriples = new ArrayList<Quad>();
		List<Quad> provenanceTriples = new ArrayList<Quad>();
		
		int index = 0;
		
		for (String predicateString : this.tuple.getHeader()) {
			
			if (CubeStructure.isPredicatePartOfCube(predicateString)) {
				String predicate = CubeStructure.getPredicate(predicateString);
				String subject = createSubject(predicate);
				String object = tuple.getData().get(index);
				
				Quad quad =  new Quad(subject,predicate,object);
				String graphLabel = getGraphLabel(quad);
				quad.setGraphLabel(graphLabel);
				
				informationTriples.add(quad);
			}
			index++;
		}
	}

	private String getGraphLabel(Quad quad) {
		// TODO Auto-generated method stub
		return null;
	}

	private String createSubject(String predicate) {
		List<Integer> indexes = CubeStructure.getPrimaryKeyIndexes(tuple.getHeader(),predicate);
		String subject = Config.getNamespace();
		for (Integer index : indexes) {
			subject += tuple.getData().get(index)+"_";
		}
		subject = replacelastUnderscoreWithSlash(subject);
		return subject;
	}

	private String replacelastUnderscoreWithSlash(String str) {
	    if (str != null && str.length() > 0 && str.charAt(str.length()-1)=='_') {
	      str = str.substring(0, str.length()-1);
	      str += "/";
	    }
	    return str;
	}
}

@@ -84,16 +84,63 @@
 .List;%0A%0A
+import dk.aau.cs.qweb.airbase.Airbase2QB4OLAP;%0A
 import d
@@ -475,16 +475,42 @@
  = 0;%0A%09%09
+System.out.println(tuple);
 %0A%09%09for (
@@ -571,29 +571,31 @@
 %0A%09%09%09if (
-CubeStructure
+Airbase2QB4OLAP
 .isPredi
@@ -652,29 +652,31 @@
 icate = 
-CubeStructure
+Airbase2QB4OLAP
 .getPred
@@ -710,26 +710,25 @@
 %09String 
-su
+o
 bject = 
 createSu
@@ -719,29 +719,95 @@
 bject = 
-createSubject
+tuple.getData().get(index);%0A%09%09%09%09List%3CString%3E levels = Airbase2QB4OLAP.getLevels
 (predica
@@ -812,64 +812,97 @@
 cate
+String
 );
+ 
 %0A%09%09%09%09
+for (
 String 
-object = tuple.getData().get(index);%0A%09%09%09%09%0A
+level : levels) %7B%0A%09%09%09%09%09String subject = createSubject(level);%0A%09
 %09%09%09%09
@@ -950,16 +950,48 @@
 bject);%0A
+%09%09%09%09%09System.out.println(quad);%0A%09
 %09%09%09%09Stri
@@ -1031,16 +1031,17 @@
 d);%0A%09%09%09%09
+%09
 quad.set
@@ -1068,21 +1068,23 @@
 l);%0A%09%09%09%09
+%09
 %0A%09%09%09%09
+%09
 informat
@@ -1105,16 +1105,22 @@
 (quad);%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%09
@@ -1272,25 +1272,21 @@
 (String 
-predicate
+level
 ) %7B%0A%09%09Li
@@ -1292,89 +1292,73 @@
 ist%3C
-Integer%3E indexes = CubeStructure.getPrimaryKeyIndexes(tuple.getHeader(),predicate
+String%3E attributes = Airbase2QB4OLAP.getAttributesUsedInIRI(level
 );%0A%09
@@ -1409,15 +1409,14 @@
 or (
-Integer
+String
  ind
@@ -1420,21 +1420,24 @@
 index : 
-index
+attribut
 es) %7B%0A%09%09
@@ -1453,34 +1453,29 @@
 += tuple.get
-Data().get
+Value
 (index)+%22_%22;
@@ -1787,10 +1787,11 @@
 str;%0A%09%7D%0A
+%0A
 %7D%0A

Change the way triples are generated.