package gov.nih.nci.ncicb.cadsr.bulkloader.parser.translate;

import gov.nih.nci.ncicb.cadsr.bulkloader.beans.castor.DataElementConceptList_ISO11179;
import gov.nih.nci.ncicb.cadsr.bulkloader.beans.castor.DataElementConcept_ISO11179;
import gov.nih.nci.ncicb.cadsr.bulkloader.beans.castor.ISO11179Elements;
import gov.nih.nci.ncicb.cadsr.domain.AdminComponentClassSchemeClassSchemeItem;
import gov.nih.nci.ncicb.cadsr.domain.DataElementConcept;
import gov.nih.nci.ncicb.cadsr.domain.DomainObjectFactory;
import gov.nih.nci.ncicb.cadsr.domain.ObjectClass;
import gov.nih.nci.ncicb.cadsr.domain.Property;

import java.util.List;

public class DataElementConceptTranslator extends AbstractTranslatorTemplate {

	@Override
	protected CaDSRObjectRegistry translateElement(ISO11179Elements iso11179Elements, CaDSRObjectRegistry objRegistry) {
		DataElementConceptList_ISO11179 isoDECList = iso11179Elements.getDataElementConcepts();
		List<DataElementConcept_ISO11179> isoDECList2 = isoDECList.getDataElementConcepts();
		for (DataElementConcept_ISO11179 isoDEC: isoDECList2) {
			DataElementConcept dec = getDEC(isoDEC, objRegistry);
			objRegistry.addDataElementConcept(isoDEC.getTagId(), dec);
		}
		
		return objRegistry;
	}
	
	private DataElementConcept getDEC(DataElementConcept_ISO11179 isoDEC, CaDSRObjectRegistry objRegistry) {
		String objRefId = isoDEC.getObjectClassRefId();
		String propRefId = isoDEC.getPropertyRefId();
		
		ObjectClass obj = objRegistry.getObjectClass(objRefId);
		Property prop = objRegistry.getProperty(propRefId);
		
		DataElementConcept dec = DomainObjectFactory.newDataElementConcept();
		dec.setObjectClass(obj);
		dec.setProperty(prop);
		
		String longName = util.getDECLongName(dec);
		String publicId = util.getIdentifier(isoDEC);
		Float version = util.getIdVersion(isoDEC);
		List<AdminComponentClassSchemeClassSchemeItem> acCSCSIList = util.getAdminComponentCSCSI(isoDEC, objRegistry);
		
		dec.setLongName(longName);
		dec.setPublicId(publicId);
		dec.setVersion(version);
		dec.setAcCsCsis(acCSCSIList);
		dec.setOrigin(util.getOrigin(isoDEC));
		
		return dec;
	}

}

@@ -380,16 +380,72 @@
 meItem;%0A
+import gov.nih.nci.ncicb.cadsr.domain.ConceptualDomain;%0A
 import g
@@ -1478,19 +1478,73 @@
 efId();%0A
+%09%09String cdRefId = isoDEC.getConceptualDomainRefId();%0A
 %09%09%0A
-
 %09%09Object
@@ -1647,16 +1647,96 @@
 RefId);%0A
+%09%09ConceptualDomain conceptualDomain = objRegistry.getConceptualDomain(cdRefId);%0A
 %09%09%0A%09%09Dat
@@ -1829,16 +1829,16 @@
 s(obj);%0A
-
 %09%09dec.se
@@ -1854,16 +1854,61 @@
 (prop);%0A
+%09%09dec.setConceptualDomain(conceptualDomain);%0A
 %09%09%0A%09%09Str

set the CD selected by the user