def importConceptsIntoArchi():

    logger.info(u"Using : %s" % fileArchimateTest)

    conceptFile = fileConceptsBatches
    logger.info(u"Loading :" + conceptFile)
    concepts = Concepts.loadConcepts(conceptFile)

    al = ArchiLib()

    # Create Subfolder
    folder = u"Implementation & Migration"
    subfolder = u"Dependancy Analysis - %s" % time.strftime(u"%Y%d%m_%H%M%S")

    attrib = dict()
    attrib[u"id"] = al.getID()
    attrib[u"name"] = subfolder
    al.insertNode(u"folder", folder, attrib)

    logger.info(u"--- Insert Nodes ---")
    insertConceptNode(al, concepts, subfolder)

    logger.info(u"--- Insert Relations ---")
    insertConceptRelation(al, concepts)

    al.outputXMLtoFile(filename=u"import_concepts.archimate")
def ImportCSVIntoArchi(fileArchimate, folder, subfolder, fileMetaEntity):

    start_time = ArchiLib.startTimer()

    logger.info(u"Using : %s" % fileArchimate)
    al = ArchiLib(fileArchimate)

    _ = al.logTypeCounts(ListOnly=True)

    al.insertNColumns(folder, subfolder, fileMetaEntity, CaseFix=False)

    al.outputXMLtoFile()

    relations = len(al.dictRel)
    nodes = len(al.dictND)

    logger.info(u"----------------------------------------------------------------------------------------")
    logger.info(u"Encountered %d errors and added %d Nodes and %d relations" % (len(al.listErrors), nodes, relations))

    ArchiLib.stopTimer(start_time)
class DrawModels(object):

    fileArchimate= None
    n = None
    al = None
    width = None
    height = None

    def __init__(self, fileArchimate):
        self.fileAchimate = fileArchimate
        self.n = 0
        self.al = ArchiLib(fileArchimate)

        self.start_time = ArchiLib.startTimer()

        self.width = u"120"
        self.height = u"55"

    def createArchimateElement(self, tag, folder, attrib):

        self.al.insertNode(tag, folder, attrib, new=False)
        AE_ID = attrib[ID]

        return AE_ID

    def createArchimateRelations(self, tag, folder, attrib):

        self.al.insertRel(tag, folder, attrib, new=False)
        AR_ID = attrib[ID]

        return AR_ID

    # <element
    #    xsi:type="archimate:ArchimateDiagramModel"
    #    id="66de3166"
    #    name="Info">

    def createDiagramModel(self, tag=None, folder=None, attrib=None):

        if tag is None and folder is None and attrib is None:
            tag = u"element"
            folder = u"Views"
            attrib = dict()
            attrib[NAME] = u"DM-TDO%d" % self.n
            attrib[ARCHI_TYPE] = DIAGRAM_MODEL
            self.al.insertNode(tag, folder, attrib)
            DMO_ID = attrib[ID]
            DMO = self.al.findDiagramModel(attrib[ID])

            if len(DMO) == 1:
                DMO = DMO[0]
            else:
                logger.error(u"Diagram Model Not Found")
                raise LookupError(u"Ops")

            return DMO
        else:
            self.al.insertNode(tag, folder, attrib)
            DMO_ID = attrib[ID]
            DMO = self.al.findDiagramModel(attrib[ID])

            if len(DMO) == 1:
                DMO = DMO[0]
            else:
                logger.error(u"Diagram Model Not Found")
                raise LookupError(u"Ops")

    # <child
    #     xsi:type="archimate:DiagramObject"
    #     id="ffc36ce0"
    #     lineColor="#000000"
    #     textAlignment="2"
    #     fillColor="#00ffff"
    #     archimateElement="4b326945">
    #  </child>

    def createDiagramObject(self, DMO, AE_ID, Bounds):

        tag = u"child"
        attrib = dict()
        attrib[ID] = self.al.getID()
        attrib[ARCHI_TYPE] = DIAGRAM_OBJECT
        attrib[u"lineColor"] = u"#000000"
        attrib[u"textAlignment"] = u"2"
        attrib[u"targetConnections"] = u""
        attrib[u"fillColor"] = u"#ffff00"
        attrib[u"archimateElement"] = AE_ID

        elm = etree.Element(tag, attrib, nsmap=NS_MAP)
        DMO.append(elm)
        DOE = self.al.findDiagramObject(attrib[ID])

        if len(DOE) == 1:
            DOE = DOE[0]
        else:
            logger.error(u"Diagram Object Not Found")
            raise LookupError(u"Ops")

        self.createBounds(DOE, Bounds)

        return DOE

    #
    # Create Bounds in DiagramObject
    # Example:
    #     <bounds
    #     x="162" y="175"
    #     width="120" height="55"
    # />
    def createBounds(self, DOE, attrib):

        tag = u"bounds"
        elm = etree.Element(tag, attrib, nsmap=NS_MAP)
        DOE.insert(0, elm)

    #
    # Create SourceConnections
    # Example:
    #     <sourceConnection
    #     xsi:type="archimate:Connection"
    #     id="592e8439"
    #     lineColor="#b1b1b1"
    #     source="4b59249d"
    #     target="c3fd7d30"
    #     relationship="27d1a38d"/>

    def createConnection(self, DOE1, DOE2, R_ID):

        tag = u"sourceConnection"
        attrib = dict()
        attrib[ARCHI_TYPE] = u"archimate:Connection"
        attrib[u"lineColor"] = u"#b1b1b1"
        attrib[ID] = self.al.getID()
        attrib[u"source"] = DOE1.get(ID)
        attrib[u"target"] = DOE2.get(ID)
        attrib[u"relationship"] = R_ID
        elm = etree.Element(tag, attrib, nsmap=NS_MAP)
        DOE1.insert(0, elm)
        SC_ID = attrib[ID]

        #
        # Aggregate target connectins
        # <child xsi:type="archimate:DiagramObject"
        #             id="52f55838"
        #             lineColor="#000000"
        #             textAlignment="2"
        #             targetConnections=""
        #             fillColor="#ffff00"
        #             archimateElement="c5369205">
        #        <bounds height="55"
        #  width="120" x="162" y="175"/>
        #      </child>

        attrib = DOE2.attrib

        if u"targetConnections" in attrib:
            attrib[u"targetConnections"] = attrib[u"targetConnections"] + " " + SC_ID
        else:
            attrib[u"targetConnections"] = " " + SC_ID

    #
    # Draw Model
    #
    def drawModel(self, elements):

        #
        # Diagram Model
        #
        DMO = self.createDiagramModel()

        for AE_ID, bnds in elements:
            #
            # DiagramObjects
            #
            self.createDiagramObject(DMO, AE_ID, bnds)

    def outputXMLtoFile(self, filename=u"DiagramModeling.archimate"):
        self.al.outputXMLtoFile(filename)

        ArchiLib.stopTimer(self.start_time)

    def outputXMLtoLog(self):
        self.al.outputXMLtoLog()

        ArchiLib.stopTimer(self.start_time)