Identifying bad EDT relations

There is an excellent article by Alex Kwitny on the subject of EDT relations that are damaged after an upgrade. Article

Read Alex’s article for all the information, but the job used to find them is below:

static void JobCreateProjWithBrokenEDTs(Args _args)
{
    #define.ProjName('BadEDTs')

    SysProjectFilterRunBase     projectFilter = new SysProjectFilterRunBase();
    ProjectNode                 projectNode;
    UtilElements                utilElements;

    SysModelElement             modelElement;
    SysModelElementType         modelElementType;
    SysModelElementData         modelElementData;

    SysDictType                 sysDictType;
    SysDictRelation             sysDictRelation;
    TableId                     tableId;
    SysDictTable                sysDictTable;
    SysDictField                sysDictField;
    FieldName                   fieldName;
    int                         i;

    void addBadEDT(SysModelElement _modelElement)
    {
        utilElements = null;
        utilElements.Name = _modelElement.Name;
        utilElements.ParentID = _modelElement.ParentId;
        utilElements.RecordType = _modelElement.ElementType;

        if (utilElements.RecordType == UtilElementType::SharedProject ||
            utilElements.RecordType == UtilElementType::PrivateProject ||
            utilElements.RecordType == UtilElementType::ClassInternalHeader ||
            utilElements.RecordType == UtilElementType::TableInternalHeader ||
            !projectFilter.doUtilElements(utilElements))
        {
            info(strfmt("@SYS316339", strfmt('%1 %2', utilElements.RecordType, utilElements.Name)));
        }
    }

    projectFilter.grouping(SysProjectGrouping::AOT);

    while select modelElement
        join Name from modelElementType
            where modelElementType.RecId == modelElement.ElementType    &&
                  modelElementType.RecId == UtilElementType::ExtendedType
        join modelElementData
            where modelElementData.ModelElement == modelElement.RecId   &&
                  modelElementData.Layer        >= (UtilEntryLevel::cus-1)
    {
        sysDictType = new sysDictType(modelElement.AxId);

        if (sysDictType)
        {
            sysDictRelation = sysDictType.relationObject();

            if (sysDictRelation)
            {
                tableId = sysDictRelation.table();

                sysDictTable = new SysDictTable(tableId);

                if (sysDictTable)
                {
                    // Found an EDT with a valid table, check if the field
                    // relations are good
                    for (i = 1; i <= sysDictRelation.lines(); i++)
                    {
                        fieldName = fieldid2name(tableId,sysDictRelation.lineExternTableValue(i));

                        sysDictField = new SysDictField(sysDictTable.id(),fieldname2id(sysDictTable.id(),fieldName));

                        if (!sysDictField)
                        {
                            // Field relation is bad on EDT
                            warning (strFmt("%1 found table, missing field on table %2", sysDictType.name(), sysDictTable.name()));
                            addBadEDT(modelElement);
                        }
                    }

                }
                else
                {
                    // Found an EDT with a broken table relation
                    warning(strFmt("%1 missing valid table", sysDictType.name()));
                    addBadEDT(modelElement);
                }
            }
        }
    }

    SysUpgradeProject::delete(#ProjName, ProjectSharedPrivate::ProjPrivate);
    projectNode = SysTreeNode::createProject(#ProjName);
    projectFilter.parmProjectNode(projectNode);
    projectFilter.write();

    info(strFmt("Created private project %1", #ProjName));
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s