How to set enum reference with default value = null in ecore and gen model? - eclipse-emf

I have an Eclass Vehicle which has an enum attribute BreakType breakType.
BreakType is defined in the same Ecore model as:
BreakType{
DRUM(0), DISC(1), BLADE(2)
}
I want to set attribute breakType default to null. for that I set following properties for breakType attribute->
DefaultLiteralValue: // it's blank
Unsettable: True
Properties of BreakType enum
Default Value : DRUM=0 // this is shown in editor UI even If i remove it from xml.
What I am getting after generating gen-model and code out of it is
BreakType breakType = DRUM // attribute set with default value
How can I set it to null, by default?

I don't think you can. If you fail to provide a default value through the defaultValueLiteral property EMF automatically picks a value appropriate to the type of the attribute. For an enumerated type, it is the first literal value that it defines.
You can always modify the generated code yourself. Or maybe you should make use of the methods generated to provide the unsettable functionality:
void unsetAttribute();
boolean isSetAttribute();
and check for the unset state instead of the null value.

Related

Access to description attribute of an Property template construct parameter

I want to use a parameterized template construct to access the attributes of a Property object to generate some output in a word document. When I use the template with some basic types (e.g. Integer or String) it works fine but when I've tried to use a Property object, I can only access the "name" attribute but not e.g. the description attribute. Using the unit test recursiveEObject-template as a starting point, my template looks like this:
{ m:template mytest(element : ecore::ENamedElement) }
{ m: element.description }
{ m:endtemplate }
And I get the following error message:
{ m:element. <---Feature description not found in EClass ENamedElement description }
I assume that the type of my parameter is just wrong and I need to change it or cast it to some derived Property child class of ENamedElement but I did not find the correct class. Any suggestions?
Kind regards
Christian
Yes you need to change the type of the parameter element to the type of the object that is holding the description feature. You will also need to import the EPackage containing the EClass.
For instance if I want to use the description of a Capella object:
{ m:template mytest(element : capellacore::CapellaElement) }
{ m: element.description }
{ m:endtemplate }
then import the following nsURI (may change according to the version of Capella):
http://www.polarsys.org/capella/core/core/1.4.0
using the template property wizard

Set default warehouse selector value of current user login with user in role on SOOrder screen

This is my coding for SiteID (Customized Existing Field)
[PXDefault(typeof(Search<PX.SM.RelationGroup.groupName,InnerJoin<PX.SM.Users, On<PX.SM.RelationGroup.groupMask,Equal<PX.SM.Users.groupMask>>,InnerJoin<INSite, On<PX.SM.RelationGroup.groupName,Equal<INSite.siteCD>>>>,Where<PX.SM.Users.pKID, Equal<Current<AccessInfo.userID>>>>),PersistingCheck = PXPersistingCheck.Nothing)]
and when publish the project it got error:
error CS0311: The type 'PX.Data.Where<PX.SM.Users.pKID,PX.Data.Equal<PX.Data.Current<PX.Data.AccessInfo.userID>>>' cannot be used as type parameter 'OrderBy' in the generic type or method 'PX.Data.Search<Field,Where,OrderBy>'. There is no implicit reference conversion from 'PX.Data.Where<PX.SM.Users.pKID,PX.Data.Equal<PX.Data.Current<PX.Data.AccessInfo.userID>>>' to 'PX.Data.IBqlOrderBy'.
error CS0311: The type 'PX.Data.InnerJoin<PX.SM.Users,PX.Data.On<PX.SM.RelationGroup.groupMask,PX.Data.Equal<PX.SM.Users.groupMask>>,PX.Data.InnerJoin<PX.Objects.IN.INSite,PX.Data.On<PX.SM.RelationGroup.groupName,PX.Data.Equal<PX.Objects.IN.INSite.siteCD>>>>' cannot be used as type parameter 'Where' in the generic type or method 'PX.Data.Search<Field,Where,OrderBy>'. There is no implicit reference conversion from 'PX.Data.InnerJoin<PX.SM.Users,PX.Data.On<PX.SM.RelationGroup.groupMask,PX.Data.Equal<PX.SM.Users.groupMask>>,PX.Data.InnerJoin<PX.Objects.IN.INSite,PX.Data.On<PX.SM.RelationGroup.groupName,PX.Data.Equal<PX.Objects.IN.INSite.siteCD>>>>' to 'PX.Data.IBqlWhere'.
enter image description here
It looks like you have wrongly modified the PXDefault attribute.
If you want to set a default value using a BQL, you must be using the Search instead of PXSelect
see the sample below
[PXDefault(typeof(Search<SOOrderType.iNDocType, Where<SOOrderType.orderType, Equal<Current<SOLineSplit.orderType>>>>), PersistingCheck = PXPersistingCheck.Nothing)]

What properties replace obsoleted Sitecore.Data.Fields.ImageField properties?

It is unclear to me from the compiler warning which fields I should be using in this code:
Sitecore.Data.Fields.ImageField imgField = item.Fields[FieldName];
if (imgField != null)
{
//Finally, save the actual values for our intended Image into the item
imgField.Src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);
imgField.MediaID = mediaItem.ID;
imgField.MediaPath = mediaItem.MediaPath;
imgField.Alt = mediaItem.Alt;
}
I get a compiler warning about imgField.Src and imgField.MediaPath. The Src warning is 'Use MediaItem property' instead... which makes little sense, because those are entirely different property types. The MediaPath warning says 'You can retrive[sic] Path from MediaItem." Well... Again, this makes very little sense because what I'm actually doing here is setting the necessary properties for MediaItem. It would be empty or NULL otherwise. Should these four lines of code just be changed to imgField.MediaItem = mediaItem? I am skeptical.
What it's trying to transition you away from doing is getting properties from the Imagefield and instead just getting the MediaItem that is referenced by the ImageField and then calling the properties that way..since it's the actual Sitecore item in the media library. Once you do that, you've got access to all the properties just like you would any other Sitecore item.

Adding SignedDataObjects (and consequently add proofOfApproval property) to an enveloped signature

I'm creating an Enveloped signature with xades4j following this statements:
Element elemToSign = doc.getDocumentElement();
XadesSigner signer = new XadesTSigningProfile(...).newSigner();
new Enveloped(signer).sign(elemToSign);
But I need to put in the signature also other properties like ProofOfApprova etc...
I see that in xades4j examples the proofOfApprovalProperties are addedto enveloped signature using different statements of signature, for example:
AllDataObjsCommitmentTypeProperty globalCommitment = AllDataObjsCommitmentTypeProperty.proofOfApproval();
CommitmentTypeProperty commitment = CommitmentTypeProperty.proofOfCreation();
DataObjectDesc obj1 = new DataObjectReference('#' + elemToSign.getAttribute("Id"))
.withTransform(new EnvelopedSignatureTransform())
.withDataObjectFormat(new DataObjectFormatProperty("text/xml", "MyEncoding")
.withDescription("Isto é uma descrição do elemento raiz")
.withDocumentationUri("http://doc1.txt")
.withDocumentationUri("http://doc2.txt"))
.withIdentifier("http://elem.root"))
.withCommitmentType(commitment)
.withDataObjectTimeStamp(dataObjsTimeStamp)
SignedDataObjects dataObjs = new SignedDataObjects(obj1)
.withCommitmentType(globalCommitment);
signer.sign(dataObjs, elemToSign);
I see here that another procedure of signature is used, more specificately the statement in which I create a DataObjectreference saying that I use "Id" attibute fo root tag is unusable for me because in input I can have any kind of xml document and I cannot know what kind of attribute (if present) I can use foe define root tag.
Briefly, can I have some examp'le code where I create an Enveloped signature and put a proofOfApproval property using "new Enveloped(signer).sign(elemToSign);", or anyway whitout knowing the xml source structure?
Thanks
M.
The proofOfApproval property has to be applied to data objects being signed, hence the need to use the SignedDataObjects class.
The Enveloped class is just a helper for straightforward scenarios. If I understood correctly you want to sign the whole XML document. The XML-Signatures spec defines that an empty URI on a reference (URI="") means exactly that. If you check the code on the Enveloped class you'll see that it adds a DataObjectReference with an empty uri.
To sum up, you'll need something like:
DataObjectDesc obj1 = new DataObjectReference("")
.withTransform(new EnvelopedSignatureTransform())
.withCommitmentType(CommitmentTypeProperty.proofOfApproval());
signer.sign(new SignedDataObjects(obj1), elemToSign);

Nullable manyToOne relationship in Doctrine 2

I've setup a simple mapping.
manyToOne:
language:
nullable: true
targetEntity: Language
inversedBy: questions
The entity then generated has the following method
public function setLanguage(\Sf2MCQ\CoreBundle\Entity\Language $language)
{
$this->language = $language;
}
But now my question is how can unset a language since I can't do
setLanguage(null) ?
I'm using the adminBundle and that's what is he is trying to do so I don't know If I should rewrite the generated method or If I'm missing something.
You can unset the language if you modify your setter so that the method's argument has default null value.
public function setLanguage(\Sf2MCQ\CoreBundle\Entity\Language $language = null)
{
$this->language = $language;
}
Then $entity->setLanguage(null) works and null will be stored after persisting the entity.
More information about typehinting allowing null value, here:
http://php.net/manual/en/language.oop5.typehinting.php