Access to description attribute of an Property template construct parameter - m2doc

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

Related

EmberJS, Helper with an "as" block

I have an Object and then I have a Decorator that consumes the Object and returns a Human-friendly representation of the Object.
For example:
object = { id: "XXX1", detail: "XXX2" }
decoratedObject { title: "The Red Building", detail: "Has 101 stories" }
I would like to use the Decorator in a template:
{{#decorator-helper object as |decoratedObject|}}
<h1>{{decoratedObject.title}}</h1>
<p>{{decoratedObject.detail}}</p>
{{/decorator-helper}}
How can I do this?
You should use a component for this.
Generally you should use helpers if you want to use them to calculate other values like this:
{{my-component value=(my-helper val)}}
If you want to use block syntax you should use a component.
As far as I know you cannot do this with helpers. Why don't you define a computed property called decoratedObject on your controller or component that would be based on object ?
decoratedObject: Ember.computed('object', {
get() {
// Build your decorated object and return it
return decoratedObject;
}
})
This would make your decorated object available in your template and dynamically rebuild it when object changes.

Unknown database type enum requested,Doctrine

when i want to generate Entity from data base i have this Error:
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it
how can i resolve this issue.
Thanks in advance
You could try to do something like this in the onBootstrap module of your Module.php, to tell Doctrine to treat your enum like a string
$em = $e->getApplication()->getServiceManager()->get('Doctrine\ORM\EntityManager');
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
Add the following line to your bootstrap.php
$entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
If you really want to work with enums and don't convert them to strings, you should implement your custom type (it's really not a big deal).
See enter link description here
But also, you have to extend list of types on your platform.
So, simplest way to do that - override useless method \Doctrine\DBAL\Types\Type::getMappedDatabaseTypes with your own so like that:
class EnumType extends Type
{
const NAME = "enum";
// ... (your implemented methods)
public function getMappedDatabaseTypes(AbstractPlatform $platform)
{
return ['enum'];
}
}
Have a fun :)

Sitecore - Image field in parameter template

If I have an image field in a parameter template, what are the steps involved in getting the URL of the image in c#?
#mdresser makes a valid point about what should and should not be a rendering parameter. However, I don't think that Sitecore intentionally made it difficult to use image fields in parameter templates. They simply built the parameter template functionality over the existing key-value pair rendering parameter functionality.
If the name of your image field on the rendering parameters template was BackgroundImage, you could use the following code to get the URL of the selected image:
var imageId = XmlUtil.GetAttribute("mediaid", XmlUtil.LoadXml(this.Parameters["BackgroundImage"]));
MediaItem imageItem = Sitecore.Context.Database.GetItem(imageId);
backgroundImageUrl = MediaManager.GetMediaUrl(imageItem);
If you don't already have a base class for your sublayouts that provides the Parameters property, you will need to also add this:
private NameValueCollection parameters;
public virtual NameValueCollection Parameters
{
get
{
if (this.parameters == null)
{
var parameters = this.Attributes["sc_parameters"];
this.parameters = string.IsNullOrEmpty(parameters)
? new NameValueCollection()
: WebUtil.ParseUrlParameters(parameters);
}
return this.parameters;
}
}
To achieve this you would have to look at how the sitecore image field renders the raw text value into an img tag. However, there is a reason that this doesn't work out of the box with sitecore; parameters templates are designed to define info about how a rendering or sublayout should render. E.g. You could use it to tell a list control to show a certain number of items etc. I'd advise against using rendering parameters for content as this will make content editing very cumbersome. If your aim is to have the content of a particular sublayout defined somewhere other than the page itself, put it into a sub item instead.
You can have a 2 separate functions to retrieve the value of image field in the parameter template that you gave to the sub layout .
First Step : Get the value associated with the parameter of image . Please use below function to retrieve the value .
/// <summary>
/// Returns a specific parameter value
/// Use this for Single-line, multiline text fields, linkfield, Image field etc.
/// </summary>
/// <param name="parameterName"></param>
/// <returns></returns>
public MediaItem GetValueFromRenderingParameter(string parameterName)
{
var item = !string.IsNullOrEmpty(_params[parameterName]) ? _params[parameterName] : string.Empty;
if(item == null)
{
return null ;
}
return Sitecore.Context.Database.GetItem(item);
}
Second step : Create another function where you can use the above mentioned function to retrieve the value of image field and use it appropriately. Here is the code snippet of the same :
Public string RenderImage()
{
Sitecore.Data.Fields.ImageField imageField =GetValueFromRenderingParameter("Image parameter name");
return MediaManager.GetMediaUrl(imageField.MediaItem) ;
}
Hope This Helps .

Writing a custom condition in WSO2 CEP with left and right argument

I want to extend the Wso2 CEP product in our needs and try to write a custom condition as indicated in this official wso2 cep link.
I am able to write an extension class that extends "org.wso2.siddhi.core.executor.conditon.AbstractGenericConditionExecutor" and implement its abstract method as indicated below:
#SiddhiExtension(namespace = "myext", function = "startswithA")
public class StringUtils extends
org.wso2.siddhi.core.executor.conditon.AbstractGenericConditionExecutor {
static Log log = LogFactory.getLog(StringUtils.class);
#Override
public boolean execute(AtomicEvent atomicEvent) {
log.error("Entered the execute method");
log.error("Atomic event to string: " + atomicEvent.toString());
return true;
}
}
when i use this extensioned method as:
from allEventsStream[myext:startswithA(name)]
insert into selectedEventsStream *;
In this situation, i want that startswithA method returns true if the name field has 'A' at the begining of it. However when i run this query in CEP the whole event drops into my execute function i.e. there is no sign to show that i send "name" field is sent to startswithA method as argument.
How can i understand which field of the stream is sent to my extended method as argument?
Also i want to write conditions like
from allEventsStream[myext:startswith('A', name)]
insert into selectedEventsStream *;
How can i achive this?
In 'AbstractGenericConditionExecutor' there's another method that gives you the set of expression executors that are included in the parameters when executor instantiates:
public void setExpressionExecutors(List<ExpressionExecutor> expressionExecutors)
You don't necessarily have to override this method and store the list, it is already stored there in the 'AbastractGenericConditionExecutor' as a list named expressionExecutors. You can pass the event to these executors to retrieve the relevant values from the event in order.
For an example, if you include a variable (like 'name') in the query (as a parameter at index 0), you'll get a 'VariableExpressionExecutor' in the list at index 0 that will fetch you the value of the variable from the event. Similarly for a constant like 'A', you'll get a different executor that will give you the value 'A' when called.
To add to Rajeev's answer, if you want to filter all the names that starts with 'A', you can override the execute method of your custom Siddhi extension similar to the following segment.
#Override
public boolean execute(AtomicEvent atomicEvent) {
if(!this.expressionExecutors.isEmpty()) {
String name = (String)this.expressionExecutors.get(0).execute(atomicEvent);
if(name.startsWith("A")) {
return true;
}
}
return false;
}
When writing the query, it would be similar to
from allEventStream[myext:startsWithA(name)]
insert into filteredStream *;
You can extend this behaviour to achieve an extension that supports
from allEventsStream[myext:startswith('A', name)]
type queries as well.
HTH,
Lasantha

Load 2 different input models in Acceleo

I'd like to load 2 different input models (a .bpel and a .wsdl) in my main template of Acceleo.
I loaded the ecore metamodels for both bpel and wsdl and I'd like to be able to use something like this:
[comment encoding = UTF-8 /]
[module generate('http:///org/eclipse/bpel/model/bpel.ecore','http://www.eclipse.org/wsdl/2003/WSDL')/]
[import org::eclipse::acceleo::module::sample::files::processJavaFile /]
[template public generate(aProcess : Process, aDefinition : Definition)]
[comment #main /]
Process Name : [aProcess.name/]
Def Location : [aDefinition.location/]
[/template]
but when I run the acceleo template I get this error:
An internal error occurred during: "Launching Generate".
Could not find public template generate in module generate.
I think I have to modify the java launcher (generate.java) because right now it can't take 2 models as arguments. Do you know how?
Thanks!
** EDIT from Kellindil suggestions:
Just to know if I understood it right, before I get to modify stuff:
I'm trying to modify the Generate() constructor.
I changed it in:
//MODIFIED CODE
public Generate(URI modelURI, URI modelURI2, File targetFolder,
List<? extends Object> arguments) {
initialize(modelURI, targetFolder, arguments);
}
In the generic case, I can see it calls the AbstractAcceleoGenerator.initialize(URI, File, List>?>), shall I call it twice, once per each model? like:
initialize(modelURI, targetFolder, arguments);
initialize(modelURI2, targetFolder, arguments);
Then, to mimic in my Generate() constructor the code that is in the super-implementation:
//NON MODIFIED ACCELEO CODE
Map<String, String> AbstractAcceleoLauncher.generate(Monitor monitor) {
File target = getTargetFolder();
if (!target.exists() && !target.mkdirs()) {
throw new IOException("target directory " + target + " couldn't be created."); //$NON-NLS-1$ //$NON-NLS-2$
}
AcceleoService service = createAcceleoService();
String[] templateNames = getTemplateNames();
Map<String, String> result = new HashMap<String, String>();
for (int i = 0; i < templateNames.length; i++) {
result.putAll(service.doGenerate(getModule(), templateNames[i], getModel(), getArguments(),
target, monitor));
}
postGenerate(getModule().eResource().getResourceSet());
originalResources.clear();
return result;
}
what shall I do? Shall I try to mimic what this method is doing in my Generate() constructor after the initialize() calls?
What you wish to do is indeed possible with Acceleo, but it is not the "default" case that the generated launcher expects.
You'll have to mark the "generate" method of the generated java class as "#generated NOT" (or remove the "#generated" annotation from its javadoc altogether). In this method, what you need to do is mimic the behavior of the super-implementation (in AbstractAcceleoLauncher) does, loading two models instead of one and passing them on to AcceleoService#doGenerate.
In other words, you will need to look at the API Acceleo provides to generate code, and use it in the way that fits your need. Our generated java launcher and the AcceleoService class are there to provide an example that fits the general use case. Changing the behavior can be done by following these samples.
You should'nt need to modify the Generate.java class. By default, it should allow you to perform the code generation.
You need to create a launch config and provide the right arguments (process and definition) in this launch config, that's all.
I don't understand the 'client.xmi' URI that is the 1st argument of your module. It looks like it is your model file, if so remove it from the arguments, which must only contain your metamodels URIs.