Is there way to pass in object into CmisExtensionElement? - apache

I have a custom aspect, and I'm trying to update it's property through OpenCMIS with CmisExtensionElement.
Currently, I'm able to update custom properties having type String with following codes:
CmisExtensionElement extension = new CmisExtensionElementImpl(namespace, "value", null, String-value);
Question is, how will I able to update custom aspect having property with type datetime, as I'm not able to pass in other than string? (If I convert date object into a string, and pass it on, it throws an error...)

Judging by this : https://chemistry.apache.org/docs/cmis-samples/samples/properties/
You should probably use something like :
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("my:dateVar1", new GregorianCalendar());
// OR
properties.put("my:dateVar2", new Date());
// update
cmisObject.updateProperties(properties);

Here is an example of code provided by Jeff Potts that shows how to do it: https://gist.github.com/jpotts/6136702

Related

Replacing Type with var for all 'Class class = new Class()' usages in Java project

I recently switched to Java 11 for a rather big project, and would like to switch to using var class = new Class() instead of Class class = new CLass().
I tried using Intellij Structural Search (and replace) for this, but its turning out to be more complex than expected.
My first attempt was $Type$ $Inst$ = new $Constructor$($Argument$);, which also matches global variables (which don't allow var).
My second attempt is:
class $Class$ {
$ReturnType$ $Method$ ($ParameterType$ $Parameter$) throws $ExceptionType$ {
$Statements$;
final $Type$ $Inst$ = new $Constructor$($Argument$);
$Statements2$;
}
}
Which misses all calls inside e.g. try blocks (since they get matched by the expressions)
Any help would be greatly appreciated!
Use your first template
$Type$ $Inst$ = new $Constructor$($Argument$);
But add a Script modifier on the $Inst$ variable with the following text:
Inst instanceof com.intellij.psi.PsiLocalVariable
Alternatively you may want to try the Local variable type can be omitted inspection that is available in IntelliJ IDEA.

Ability to set the context of the expression

Is there a way to set the context of the expression in Dynamic Expresso library, so that we can do something like the following:
interpreter.Eval("FirstName", new Parameter("person", new { FirstName="Homer", LastName="Simpson"}));
rather than
interpreter.Eval("person.FirstName", new Parameter("person", new { FirstName="Homer", LastName="Simpson"}));
Maybe we could have a another option that would say that the first parameter is to be used as the context for the expression.
I guess there could also be another version of Parse and Eval methods that simply takes the expression text and a simple object value that will serve as the expression context.
Other than that and the lack of support for dynamic types, I am really liking this library. I had worked on something similar, but had not added support for extension methods and generic method calls.
Thanks for the great library,
Neal
There isn't a built-in solution but you can simulate it in many ways:
Option 1: Inject an expression
var workingContext = new { FirstName = "homer" };
var workingContextExpression = Expression.Constant(workingContext);
var firstNameExpression = Expression.Property(workingContextExpression, "FirstName");
var interpreter = new Interpreter();
interpreter.SetExpression("FirstName", firstNameExpression);
Assert.AreEqual(workingContext.FirstName, interpreter.Eval("FirstName"));
Basically I inject an expression using SetExpression method. The injected expression is the property that you want to be available.
Option 2: Use this/me/it variable
You can inject a variable that will contain your working object. I usually call it this (or me or it depending on the application).
var workingContext = new { FirstName = "homer" };
var interpreter = new Interpreter();
interpreter.SetVariable("this", workingContext);
Assert.AreEqual(workingContext.FirstName, interpreter.Eval("this.FirstName"));
Option 3: A combination of the previous solutions
var workingContext = new { FirstName = "homer" };
var interpreter = new Interpreter();
interpreter.SetVariable("this", workingContext);
var firstNameExpression = interpreter.Parse("this.FirstName").LambdaExpression.Body;
interpreter.SetExpression("FirstName", firstNameExpression);
Assert.AreEqual(workingContext.FirstName, interpreter.Eval("FirstName"));
Equal to the first solution but I generate the expression using the parser itself.
Consider that all solutions assume that you must have an Interpreter instance for each context.
Disclaimer: I'm the author of Dynamic Expresso library.
Starting with DynamicExpresso v2.13.0, it's possible to define a variable named "this", that will be used for implicit resolution:
var target = new Interpreter();
target.SetVariable("this", new { FirstName="Homer", LastName="Simpson"});
// 'this' variable is used implicitly
Assert.AreEqual("Homer", target.Eval("FirstName"));
// 'this' variable can also be used explicitly
Assert.AreEqual("Homer", target.Eval("this.FirstName"));

Using dynamic types with expresso

I would like to use a dynamic value as a parameter.
E.g.
dynamic dyn = new ExpandoObject();
dyn.Foo = "bar";
var bar = new Interpreter().Eval("d.Foo", new Parameter("d", dyn));
Assert.AreEqual("bar", bar.ToString());
But I get an error saying "No property or field 'Foo' exists in type 'ExpandoObject'" ?
Is this supposed to be possible?
Regards, Niels
Unfortunately for now dynamics (ExpandoObject) are not supported. I will consider this feature for the next release.
A possible workaround is to use anonymous objects:
dynamic dyn = new ExpandoObject();
dyn.Foo = "bar";
var bar = new Interpreter().Eval("d.Foo", new Parameter("d", new { Foo = dyn.Foo }));
Consider that in this case the property is evaluated when you create the parameter.
You can also convert a dynamic into an anonymous type (see Cast ExpandoObject to anonymous type) but the result is not very different.
Disclaimer: I'm the creator of Dynamic Expresso library.
Expression Evaluator supports dynamics (ExpandoObject). It supports method calls, property and index accessors, get and set. If you do encounter an error with dynamics please let me know as dynamics is relatively newly supported.

Creating new smartform data using Ektron ContentTypes

Ektron 8.0.1 SP1
I am using SmartForms and Content Types to read (and hopefully write) data. I can read data but now I am attempting to write a new record similar to the following.
ContentTypeManager<member> contentTypeManager = new ContentTypeManager<member>();
ContentType<member> newmem = new ContentType<member>();
newmem.SmartForm.details.field1 = "Chuck"; // This line throws 'Object reference not set to an instance of an object.' error
newmem.SmartForm.details.field2 = "Norris";
contentTypeManager.Update(newmem);
I get the error "Object reference not set to an instance of an object." for that first assignment line. What am I missing?
I am having trouble finding good documentation on ContentTypes for 8.0.1 now that the Ektron website has been redesigned.
Thx.
Thanks for clarifying, to ADD content to a folder that has a smartform assigned to it, the basic code block should get you started: (Note: the Html attribute of the content is simply the xml matched to the schema you created)
Ektron.Cms.Framework.Content.ContentManager cmanager = new Cms.Framework.Content.ContentManager();
Ektron.Cms.ContentData cdata = new ContentData();
cdata.FolderId = 0;
cdata.XmlConfiguration.Id = 0; //SMARTFORM ID HERE
cdata.Html = "<root><field1>field1 value</field1><field2>field2 value</field2></root>";
cmanager.Add(cdata);
You could update ContentTypes.cs to include an Add method. Just copy the Update method and change contentManager.Update to contentManager.Add.
public void Add(ContentType<T> contentType)
{
Initialize();
contentType.Content.Html = Ektron.Cms.EkXml.Serialize(typeof(T), contentType.SmartForm);
contentManager.Add(contentType.Content);
}
Unfortunately, contentManager.Add returns void. Ideally it should return the new content ID.

Unable to create SqlMap for PersistenceClient with Cairngorm Persistence Library

i am trying to create a persistence client object in the following way:
var create:Create = new Create();
create.sql = "CREATE TABLE IF NOT EXISTS REPOFILE( REPOFILEID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, CHECKSUM TEXT, BYTES INTEGER, CREATED INTEGER, UPDATED INTEGER, ISDIRECTORY INTEGER )";
var sqlMap:SqlMap = new SqlMap( { createRepoFileTable : create } );
connectionManager = new ConnectionManagerFactory().createConnectionManager();
persistenceClient = new PersistenceClient( sqlMap, connectionManager );
the problem i am encountering is that the "map" property of the sqlmap stays not retrievable even though there is a valid "_maps" array inside the sqlmap object.
maps [] (#b812d09)
[0] Object (#b103d61)
createRepoFileTable com.adobe.cairngorm.persistence.api.grammar.Create (#b103a91)
length 1
when trying to execute the create table sql, the statement factory complains:
Error: SQLERROR0014: Statement 'createRepoFileTable' not found in SQL map
somehow the sqlmap class is unable to copy the properties of the object passed to it to the map property using the ObjectUtil class.
i do not want to use an mxml file and i also do not want to use spicelib like in the example.
what am i doing wrong here?
so i figured out that in my case somehow the calls in the SqlMap class to the spicelib components didn't work:
var classInfo:ClassInfo=ClassInfo.forInstance(source);
var properties:Array=classInfo.getProperties();
the properties array was always empty.
however, i took the persistence lib's source code and changed the loop in the ObjectUtil's to go over the object's properties directly:
for (var propertyName:String in source)
now it works, although i am not really happy having modified the ObjectUtil class... maybe someone has a better take on this.