Menu

Add a new Typologie class?

Marco
2021-09-06
2024-06-24
  • Marco

    Marco - 2021-09-06

    Hi,

    currently I testing if itop can be used by us as an inventory tool. The first look is simple great!

    I have already created a new CI with different custom fields. For my example I followed this great tutorial:
    https://www.itophub.io/wiki/page?id=2_2_0%3Acustomization%3Aadd-class-sample.

    Is there a way, or a good tutorial, how to create a field which reference to a new created typology class ?

    As an example, I would like to be able to add custom entries (LCD, CRT, Plasma,...) to the "Technology" field on my CI "Monitor".

    Thx for any help!

    Marco

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2021-09-06

    You'll need to extend the abstract class typology with your new custom typology and use an AttributeExternalKey to the monitor pointing to this new typology class.

    You can find some examples (such as Brand or Model) in datamodel-production.xml (found in the "data" folder of iTop after installation)

     
    • Marco

      Marco - 2021-09-08

      Hi Jeffry,

      I create a new, emty module with the generator from itop (see here), then I installed the new modul and create a new datamodel (In my Case I want create a new typolgie class "room" (german: Raum):

      <?xml version="1.0" encoding="UTF-8"?>
      <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
        <constants>
        </constants>
        <classes>
              <class id="Raum" _delta="define">
               <parent>Typology</parent>
                <properties>
                  <category>bizmodel,searchable,structure</category>
                  <abstract>false</abstract>
                  <key_type>autoincrement</key_type>
                  <db_table>company_raum</db_table>
                  <db_key_field>id</db_key_field>
                  <db_final_class_field/>
                  <naming>
                   <attributes>
                   <attribute id="raum"/>
                   </attributes>
                  </naming>
                  <order>
                   <columns>
                    <column id="raum" ascending="true"/>
                  </columns>
                  </order>
                  <display_template/>
                  <icon/>
                  <reconciliation>
                    <attributes>
                      <attribute id="raum"/>
                    </attributes>
                  </reconciliation>
                  <uniqueness_rules>
                    <rule id="raum">
                      <attributes>
                        <attribute id="raum"/>
                      </attributes>
                      <is_blocking>true</is_blocking>
                    </rule>
                  </uniqueness_rules>
                </properties>
                <fields>
                 <field id="raumnummer" xsi:type="AttributeString" _delta="define">
                   <sql>raumnummer</sql>
                   <default_value/>
                   <is_null_allowed>true</is_null_allowed>
                   <display_style>radio_horizontal</display_style>
                 </field>
                </fields>
                <methods/>
                <presentation>
                  <details>
                    <items>
                      <item id="raum">
                        <rank>10</rank>
                      </item>
                      <item id="physicaldevice_list">
                        <rank>20</rank>
                      </item>
                    </items>
                  </details>
                  <search>
                    <items>
                      <item id="raum">
                        <rank>10</rank>
                      </item>
                    </items>
                  </search>
                  <list>
                    <items>
                      <item id="raum">
                        <rank>10</rank>
                      </item>
                    </items>
                  </list>
                </presentation>
              </class>
        </classes>
        <menus>
         <menu id="Typology" xsi:type="DashboardMenuNode" _delta="must_exist">
          <definition>
            <cells>
              <cell id="0" _delta="must_exist">
                <dashlets>
                  <dashlet id="99" xsi:type="DashletBadge" _delta="define">
                    <rank>10</rank>
                    <class>Raum</class>
                  </dashlet>
                </dashlets>
              </cell>
            </cells>
          </definition>
         </menu>
        </menus>
        <user_rights>
          <groups>
          </groups>
          <profiles>
          </profiles>
        </user_rights>
      </itop_design>
      

      My Problem now is, when i check the itop data model consistency all looks good (see attachment), but the table company_raum wouldn't create in mysql.

      Under the typologie menue i can see following error:
      DBObjectSearch::__construct called for an invalid class: "Raum"

      Can you tell me what I#m doing wrong?

       
      • Jeffrey Bostoen

        Jeffrey Bostoen - 2021-09-08

        We'd need to see all your files; but some things to consider: it's best to keep the database table names in English (not required though); you also seem to refer to an attribute you call "Raum" while you only define the attribute "raumnummer" ? (also here it might be best to keep the names in English; and then use the dictionary files for translations)

         
  • Marco

    Marco - 2021-09-09

    Hi,

    i changed the names in english and changed the atribute raummnummer to raum:

    <?xml version="1.0" encoding="UTF-8"?>
    <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
      <constants>
      </constants>
      <classes>
            <class id="Room" _delta="define">
             <parent>Typology</parent>
              <properties>
                <category>bizmodel,searchable,structure</category>
                <abstract>false</abstract>
                <key_type>autoincrement</key_type>
                <db_table>company_room</db_table>
                <db_key_field>id</db_key_field>
                <db_final_class_field/>
                <naming>
                 <attributes>
                 <attribute id="room"/>
                 </attributes>
                </naming>
                <order>
                 <columns>
                  <column id="room" ascending="true"/>
                </columns>
                </order>
                <display_template/>
                <icon/>
                <reconciliation>
                  <attributes>
                    <attribute id="room"/>
                  </attributes>
                </reconciliation>
                <uniqueness_rules>
                  <rule id="room">
                    <attributes>
                      <attribute id="room"/>
                    </attributes>
                    <is_blocking>true</is_blocking>
                  </rule>
                </uniqueness_rules>
              </properties>
              <fields>
               <field id="room" xsi:type="AttributeString" _delta="define">
                 <sql>room</sql>
                 <default_value/>
                 <is_null_allowed>true</is_null_allowed>
                 <display_style>radio_horizontal</display_style>
               </field>
              </fields>
              <methods/>
              <presentation>
                <details>
                  <items>
                    <item id="room">
                      <rank>10</rank>
                    </item>
                    <item id="physicaldevice_list">
                      <rank>20</rank>
                    </item>
                  </items>
                </details>
                <search>
                  <items>
                    <item id="room">
                      <rank>10</rank>
                    </item>
                  </items>
                </search>
                <list>
                  <items>
                    <item id="room">
                      <rank>10</rank>
                    </item>
                  </items>
                </list>
              </presentation>
            </class>
      </classes>
      <menus>
       <menu id="Typology" xsi:type="DashboardMenuNode" _delta="must_exist">
        <definition>
          <cells>
            <cell id="0" _delta="must_exist">
              <dashlets>
                <dashlet id="99" xsi:type="DashletBadge" _delta="define">
                  <rank>10</rank>
                  <class>Room</class>
                </dashlet>
              </dashlets>
            </cell>
          </cells>
        </definition>
       </menu>
      </menus>
      <user_rights>
        <groups>
        </groups>
        <profiles>
        </profiles>
      </user_rights>
    </itop_design>
    

    Here the content of the other files:
    en.dict.company-typologie.php

    <?php
    /**
     * Localized data
     *
     * @copyright   Copyright (C) 2013 XXXXX
     * @license     http://opensource.org/licenses/AGPL-3.0
     */
    
    Dict::Add('EN US', 'English', 'English', array(
            // Dictionary entries go here
    ));
    ?>
    

    model.company-typologie.php

    <?php
    
    // PHP Data Model definition file
    
    // WARNING - WARNING - WARNING
    // DO NOT EDIT THIS FILE (unless you know what you are doing)
    //
    // If you use supply a datamodel.xxxx.xml file with your module
    // the this file WILL BE overwritten by the compilation of the
    // module (during the setup) if the datamodel.xxxx.xml file
    // contains the definition of new classes or menus.
    //
    // The recommended way to define new classes (for iTop 2.0) is via the XML definition.
    // This file remains in the module's template only for the cases where there is:
    // - either no new class or menu defined in the XML file
    // - or no XML file at all supplied by the module
    

    module.company-typologie.php

    <?php
    //
    // iTop module definition file
    //
    
    SetupWebPage::AddModule(
            __FILE__, // Path to the current file, all other file names are relative to the directory containing this file
            'company_typologie/1.0.0',
            array(
                    // Identification
                    //
                    'label' => 'Typologie Ergänzungen (Company)',
                    'category' => 'business',
    
                    // Setup
                    //
                    'dependencies' => array(
    
                    ),
                    'mandatory' => false,
                    'visible' => true,
    
                    // Components
                    //
                    'datamodel' => array(
                            'model.company-typologie.php'
                    ),
                    'webservice' => array(
    
                    ),
                    'data.struct' => array(
                            // add your 'structure' definition XML files here,
                    ),
                    'data.sample' => array(
                            // add your sample data XML files here,
                    ),
    
                    // Documentation
                    //
                    'doc.manual_setup' => '', // hyperlink to manual setup documentation, if any
                    'doc.more_information' => '', // hyperlink to more information, if any
    
                    // Default settings
                    //
                    'settings' => array(
                            // Module specific settings go here, if any
                    ),
            )
    );
    
    
    ?>
    
     
  • Marco

    Marco - 2021-09-21

    Jeffrey, do you have a idea, what i'm doing wrong?

     
  • Ekaterina Latipova

        'dependencies' => array(
                        'itop-config-mgmt/3.1.0',
        ),
    

    Check your dependencies

     

    Last edit: Ekaterina Latipova 2024-06-24

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.