I'm trying to create an extension to make some server fileds mandatory.
I am at the xml validation of the datamodel from the data model toolkit.
Some of these fields are originaly declared in the Server class (from dataodel.itop-config-mgmt.xml) --> no pb with these one
But some of the fields are heritated from parent classes (like DatacenterDevice or even from FunctionnalCI parent classes).
I guess it would be possible to "redefine" the fields from these parent classes, but I don't want to impact other teams (network guys with their network devices)
Is it possible to "redefine" a field in a class that is heritated from a parent class, without redefining the other "child classes" fields?
thx a lot in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think you can redefine that fields should (not) be mandatory or readonly on the child classes. Have you tried redefining them on the child classes, rather than on the parent? (as long as you keep them the same attribute type)
Last edit: Jeffrey Bostoen 2019-07-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yes I tried to redefine these fields inside the server class, but it says the fields don't exists in this class (normal. for example the location_name is heritated from FunctuonnalCi class)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I assume you tried _delta="redefine" AND added a proper requirement first so you can override the Server class; what happens if you try _delta="define" ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If I try _delta="define" I have the following error:
An error occured while processing the PHP files of the data model:
Declaration of Server: attempting to redeclare the inherited attribute 'location_name', originaly declared in PhysicalDevice
Check the PHP files describing the data model before running the toolkit again !
Last edit: vercetty92 2019-07-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If the classes having the field you want to make mandatory have no lifecycle, there is a way of doing it, but it's not a nice one as it could conflit with other extensions or future upgrades, so you have been warned 🙊
You can overload the GetInitialStateAttributeFlags and GetAttributeFlags methods of you class to return the OPT_ATT_MANDATORY flag for your field.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@glajarige, I looked at the parent class and there is no lifecycle . does that mean that it's not possible to use the clean way? (using of lifecycle) is it still possible to create a distinct lifecycle for class B as suggested by @pgoiffon ?
I'm not a pro in dev or xml so I'm still learning here^^
thx a lot
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can add a lifecycle on a child class yes. Just make sure it has a enum attribute that will carry the lifecycle state, then add the lifecycle tag like in the XML reference here :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The first server field i'm trying to make mandatory is the location_name
despite the documentation, I confess I didn't really undertand how a lifecycle is working^^ (in the doc it's onyl written "Lifecycle: states and transitions")
I tried to find some inspiration by looking at the existing lifecycle present in the itop code, but not sure if these lifecycle ahve the same goal as the one I have (overwrite the is_null_allowed heritated from parent class). Do you know if there is a plce where I can see a good example of such thing?
I also tried to understand what you said about enum attribute and state. So basicaly the attribute need to be something heritated from the parent class?
I see in the parent class (where the "location_name" field is declared), that there is also :
<attribute id="location_name"/>
does that mean, that inside the lifecycle I put in the child class I need to do:
<attribute>location_name</attribute>
Also, for the state I don't know what to writte^^
Sorry to ask for all this help^^
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Creating a lifecycle on the Server class just to make 'location_id' mandatory on the Server class, also this field is defined on the parent PhysicalDevice class, is a bit too much. It will work, but that's a lot of work.
The other option, to remove 'location_id' field from PhysicalDevice and recreate a 'site_id' field on every final classes to be free to change their 'mandatory' aspect, is also painfull and will break the Location tab which display PhysicalDevices located on that location.
The option by which you overload the GetInitialStateAttributeFlags and GetAttributeFlags methods of you class to return the OPT_ATT_MANDATORY flag for your field, is by far the quickest and simplest method for doing this.
The 2 methods below should be declared on the Server class encapsulated in XML code. Check here for how to encapsulate a PHP method in an XML definition
Then put this XML in an iTop extension with the right dependencies and it should do the work
Ok there are some risk with this method: if another extension does the same on the Class Server (overload those methods), then the last extension loaded during iTop Setup will win and impose its behavior. Not an high risk so,...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi @cisou, I mentioned location_name, but my goal is to make mandatory more fields than that, anyway if I can have at least one working example with location_name, it's a good start.
I will try what you suggested and will let you know.
thanks a lot
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just to be clear, don't do it on 'location_name' as this will have no effect.
'location_name' is an ExternalField, which means a calculated value, not stored in DB and not even proposed in the creation/edit Form.
The methods apply to multiple fields, just change the if condition with || or in_array
if (in_array($sAttCode,array('location_id','model_id','brand_id')))
{ ...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ok so it seems I will not be able to try it because the idea of making the fields mandatory have not been approved by everyone lol, but anyways I would have learned a lot but trying to do that, and if One day I finally need to do try that again, I will let you know (or if someone else is interested)
thanks again for your help guys
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm trying to create an extension to make some server fileds mandatory.
I am at the xml validation of the datamodel from the data model toolkit.
Some of these fields are originaly declared in the Server class (from dataodel.itop-config-mgmt.xml) --> no pb with these one
But some of the fields are heritated from parent classes (like DatacenterDevice or even from FunctionnalCI parent classes).
I guess it would be possible to "redefine" the fields from these parent classes, but I don't want to impact other teams (network guys with their network devices)
Is it possible to "redefine" a field in a class that is heritated from a parent class, without redefining the other "child classes" fields?
thx a lot in advance
Hello,
No you can't redefine in class B a field that is defined in parent class A.
A solution might be to have a distinct lifecycle for class B ?
I think you can redefine that fields should (not) be mandatory or readonly on the child classes. Have you tried redefining them on the child classes, rather than on the parent? (as long as you keep them the same attribute type)
Last edit: Jeffrey Bostoen 2019-07-03
yes I tried to redefine these fields inside the server class, but it says the fields don't exists in this class (normal. for example the location_name is heritated from FunctuonnalCi class)
I assume you tried
_delta="redefine"AND added a proper requirement first so you can override the Server class; what happens if you try_delta="define"?yes I used
_delta="redefine".If I try
_delta="define"I have the following error:Last edit: vercetty92 2019-07-03
Then I'm afraid it's a limitation of iTop (I think I stumbled upon that myself once), if someone from Combodo can confirm?
See my answer above :)
If the classes having the field you want to make mandatory have no lifecycle, there is a way of doing it, but it's not a nice one as it could conflit with other extensions or future upgrades, so you have been warned 🙊
You can overload the
GetInitialStateAttributeFlagsandGetAttributeFlagsmethods of you class to return theOPT_ATT_MANDATORYflag for your field.Thx for your answers guys.
My goal is not to do something "dirty".
@glajarige, I looked at the parent class and there is no lifecycle . does that mean that it's not possible to use the clean way? (using of lifecycle) is it still possible to create a distinct lifecycle for class B as suggested by @pgoiffon ?
I'm not a pro in dev or xml so I'm still learning here^^
thx a lot
You can add a lifecycle on a child class yes. Just make sure it has a enum attribute that will carry the lifecycle state, then add the lifecycle tag like in the XML reference here :)
Hi @glajarigen thanks again for the explanation.
The first server field i'm trying to make mandatory is the location_name
despite the documentation, I confess I didn't really undertand how a lifecycle is working^^ (in the doc it's onyl written "Lifecycle: states and transitions")
Basically do I need to create such structure ?
I tried to find some inspiration by looking at the existing lifecycle present in the itop code, but not sure if these lifecycle ahve the same goal as the one I have (overwrite the is_null_allowed heritated from parent class). Do you know if there is a plce where I can see a good example of such thing?
I also tried to understand what you said about enum attribute and state. So basicaly the attribute need to be something heritated from the parent class?
I see in the parent class (where the "location_name" field is declared), that there is also :
does that mean, that inside the lifecycle I put in the child class I need to do:
Also, for the state I don't know what to writte^^
Sorry to ask for all this help^^
Thanks
Creating a lifecycle on the Server class just to make 'location_id' mandatory on the Server class, also this field is defined on the parent PhysicalDevice class, is a bit too much. It will work, but that's a lot of work.
The other option, to remove 'location_id' field from PhysicalDevice and recreate a 'site_id' field on every final classes to be free to change their 'mandatory' aspect, is also painfull and will break the Location tab which display PhysicalDevices located on that location.
The option by which you overload the GetInitialStateAttributeFlags and GetAttributeFlags methods of you class to return the OPT_ATT_MANDATORY flag for your field, is by far the quickest and simplest method for doing this.
The 2 methods below should be declared on the Server class encapsulated in XML code. Check here for how to encapsulate a PHP method in an XML definition
Then put this XML in an iTop extension with the right dependencies and it should do the work
Ok there are some risk with this method: if another extension does the same on the Class Server (overload those methods), then the last extension loaded during iTop Setup will win and impose its behavior. Not an high risk so,...
Hi @cisou, I mentioned location_name, but my goal is to make mandatory more fields than that, anyway if I can have at least one working example with location_name, it's a good start.
I will try what you suggested and will let you know.
thanks a lot
Just to be clear, don't do it on 'location_name' as this will have no effect.
'location_name' is an ExternalField, which means a calculated value, not stored in DB and not even proposed in the creation/edit Form.
The methods apply to multiple fields, just change the if condition with || or in_array
ok noted, thanks again, keep you informed^^
ok so it seems I will not be able to try it because the idea of making the fields mandatory have not been approved by everyone lol, but anyways I would have learned a lot but trying to do that, and if One day I finally need to do try that again, I will let you know (or if someone else is interested)
thanks again for your help guys