def filterTargetDataSet(self, filterAttributeType, dataToBeFiltered):
        filteredData = []
        for key in self.parameterMap.keys():
            filterValue = self.parameterMap[key]
            if str.upper(key).find("ATTRIBUTEVALUEEQUALS") != -1:
                for data in dataToBeFiltered:
                    # Find the resourceId
                    assetObj = Asset(data['resourceId'])
                    attributesResponse = assetObj.fetchAttributes()
                    attributesResponseList = attributesResponse[
                        'attributeReference']

                    # Loop through the attributesResponseList to check whether specified filterValue has been set
                    for listIndex in range(0, len(attributesResponseList)):
                        attributeResponseMap = attributesResponseList[
                            listIndex]
                        # key = attributeResponseMap['resourceId'] + ' -> ' + attributeResponseMap['labelReference']['signifier']
                        attributeType = attributeResponseMap['labelReference'][
                            'signifier']
                        if attributeType == filterAttributeType:
                            cleanedValue = AttributeFilter.cleanhtml(
                                attributeResponseMap['value'])
                            if cleanedValue == filterValue:
                                filteredData.append(data)

        return filteredData
    def filterAttributeDataSet(self, dataToBeFiltered):
        filteredData = []
        i = 0

        for data in dataToBeFiltered:
            assetObj = Asset(data['resourceId'])
            # Find out whether there are any attributes tied to the asset:
            possibleAttributesList = assetObj.fetchPossibleAttributesTypes()
            if len(possibleAttributesList['attributeType']) > 0:
                # Fetch attributes for the resourceId
                attributesResponse = assetObj.fetchAttributes()
                attributesResponseList = attributesResponse[
                    'attributeReference']

                # Loop through the attributesResponseList to check whether specified filterValue has been set
                for listIndex in range(0, len(attributesResponseList)):
                    attributeResponseMap = attributesResponseList[listIndex]
                    attributeType = attributeResponseMap['labelReference'][
                        'signifier']
                    if attributeType == self.parameterMap[
                            'attributeTypeEquals']:
                        filteredData.append(data)
                i += 1

        return filteredData
Beispiel #3
0
    def checkCompletion(inputAssetData, detailedFile):
        finalMap = {}
        finalResultList = []
        # Fetch Completion Status for all the assets
        for i in range(0, len(inputAssetData)):

            targetDataMap = {}
            assetObj = Asset(inputAssetData[i]['resourceId'])
            for detailType in ProcessMaps.outputParameterList:
                targetDataMap[detailType] = assetObj.fetchAssetAssetDetails(
                    detailType, inputAssetData[i])

            # Find possible attributes types and relations types
            possibleRelationsAndAttributesResponse = assetObj.fetchPossibleRelationsTypesAndAttributesTypes(
            )
            possibleAttributeTypesList = []
            possibleRelationTypesList = []

            if possibleRelationsAndAttributesResponse != 'No Data Found':
                possibleRelationsAndAttributesList = possibleRelationsAndAttributesResponse[
                    'representationReference']
                for k in range(0, len(possibleRelationsAndAttributesList)):
                    if 'descriptionReference' in possibleRelationsAndAttributesList[
                            k].keys():
                        possibleAttributeTypesList.append(
                            possibleRelationsAndAttributesList[k]['signifier'])

                    if 'role' in possibleRelationsAndAttributesList[k].keys():
                        if possibleRelationsAndAttributesList[k][
                                'role'] not in possibleRelationTypesList:
                            possibleRelationTypesList.append(
                                possibleRelationsAndAttributesList[k]['role'])
                        if possibleRelationsAndAttributesList[k][
                                'coRole'] not in possibleRelationTypesList:
                            possibleRelationTypesList.append(
                                possibleRelationsAndAttributesList[k]
                                ['coRole'])
            completion = 'Y'
            # Fetch relation types that have been defined for an asset
            targetDataRelationsList = []
            relationsResponse = assetObj.fetchRelations()
            if relationsResponse != 'No Data Found':
                # Add all the relation types that have a value
                for relationResponseMap in relationsResponse:
                    for innerRelationsMap in relationResponseMap['relation']:
                        relationType = ''
                        if 'resourceType' in innerRelationsMap[
                                'typeReference']['headTerm']:
                            relationType = innerRelationsMap['typeReference'][
                                'headTerm']['resourceType']

                        if relationType != "CRT":
                            targetDataRelationsList.append(
                                innerRelationsMap['typeReference']['role'])
                            targetDataRelationsList.append(
                                innerRelationsMap['typeReference']['coRole'])

                # Determine whether all relation types have been defined
                for possibleRelationType in possibleRelationTypesList:
                    if possibleRelationType not in targetDataRelationsList:
                        targetDataMap['Completion-Category'] = 'N'
                        completion = 'N'
                        break

            # Fetch attributes types that have been defined for an asset
            if completion == 'Y':
                targetDataAttributesList = []
                attributesResponse = assetObj.fetchAttributes()
                if attributesResponse != 'No Data Found':
                    attributesResponseList = attributesResponse[
                        'attributeReference']

                    for listIndex in range(0, len(attributesResponseList)):
                        attributeResponseMap = attributesResponseList[
                            listIndex]
                        key = attributeResponseMap['labelReference'][
                            'signifier']
                        if key not in targetDataAttributesList:
                            targetDataAttributesList.append(key)

                    # Add all the attribute types that don't have a value
                    for possibleAttribute in possibleAttributeTypesList:
                        if possibleAttribute not in targetDataAttributesList:
                            targetDataMap['Completion-Category'] = 'N'
                            completion = 'N'
                            break

            if 'Completion-Category' not in targetDataMap.keys():
                targetDataMap['Completion-Category'] = 'Y'

            finalMap['Asset Details'] = targetDataMap
            finalResultList.append(finalMap)
            finalMap = {}

        #Print the results to a file
        fileName = CreateDataFile.createDataFile(finalResultList, detailedFile)
        return fileName
                                            # Add all the relation types that don't have a value
                                            for possibleRelationType in possibleRelationTypesList:
                                                for roleMap in possibleRelationType:
                                                    if possibleRelationType[
                                                            roleMap] not in targetDataRelationsMap.keys(
                                                            ):
                                                        targetDataRelationsMap[
                                                            possibleRelationType[
                                                                roleMap]] = ''

                                # Find the Attributes
                                if outputParameter == 'Attributes' and len(
                                        possibleAttributeTypesList) > 0:

                                    targetDataAttributesMap = {}
                                    attributesResponse = assetObj.fetchAttributes(
                                    )
                                    attributesResponseList = attributesResponse[
                                        'attributeReference']

                                    if outputParameterList == 'All':
                                        # Add all the attribute types that have a value
                                        for listIndex in range(
                                                0,
                                                len(attributesResponseList)):
                                            attributeResponseMap = attributesResponseList[
                                                listIndex]
                                            existingKeyValue = []
                                            # key = attributeResponseMap['resourceId'] + ' -> ' + attributeResponseMap['labelReference']['signifier']
                                            key = attributeResponseMap[
                                                'labelReference']['signifier']
                                            cleanedKeyValue = cleanhtml(