I had posting in alfresco hub , couldnt get solution yet.
I was trying to convert javascript API code to java API which move files to different content store(' storeB'). We have storeB defined in - 'content-store-selector-context.xml'. We are using Enterrprises version of Alfresco 5.2.
java script code as follows , - Works perfectly fine . its working code.
for each (var n in node.children) {
if (n.isDocument) {
//Apply script for moving files to DMS Store 01
n.removeAspect("cm:versionable");
n.addAspect("cm:storeSelector");
n.properties['cm:storeName'] = "storeB";
n.save();
}
}
Below is Java API Code - But this code is not moving files to 'storeB'. Is there anything i am missing ?
Is there any similiar method available in java APIs.
List<ChildAssociationRef> children = nodeService.getChildAssocs(dayFolderRef);
Map<QName, Serializable> aspectsProps = new HashMap<QName, Serializable>(1);
aspectsProps.put(ContentModel.PROP_STORE_NAME, "storeB");
LOG.info("Folder::" + dayFolderRef.getId());
LOG.info("Number of Subfolder to be moved is ::" + children.size());
for (ChildAssociationRef childAssoc : children) {
NodeRef childNodeRef = childAssoc.getChildRef();
if (ContentModel.TYPE_CONTENT.equals(nodeService.getType(childNodeRef))) {
LOG.info("Moving the file to secondary storae "+childNodeRef.getId());
nodeService.removeAspect(childNodeRef, ContentModel.ASPECT_VERSIONABLE);
nodeService.addAspect(childNodeRef, ContentModel.ASPECT_STORE_SELECTOR, aspectsProps);
}
}
I can see a save method is java script API. based on response recieved Alfresco forum , there is no save method in javascript API. Java API run in transactions , so will commit eventually . But i can see from DB using the below SQL -
SELECT count(*)
FROM alf_content_url
WHERE orphan_time IS NOT NULL;
the above SQL returns same count after executing the code , so no DB updates happening. Anything wrong ?
Any help , appreciated
Regards
Brijesh
I don't see why that would not work, are you positive you're even entering that method? Try adding the content store selector aspect with no properties map, then add the content store name property with setProperty method separately.
Related
I have run into a road block developing my Codename One app. One of my classes in my project parses 3 specific html "td" elements from a website and saves the text to a string where I then input that text data into a Codename One multibutton. I originally used jSoup for this operation but soon realized that Codename One doesn't support 3rd party jar files so I used this method as shown below.
public void showOilPrice() {
if (current != null) {
current.show();
return;
}
WebBrowser b = new WebBrowser() {
#Override
public void onLoad(String url) {
BrowserComponent c = (BrowserComponent) this.getInternal();
JavascriptContext ctx = new JavascriptContext(c);
String wtiLast = (String) ctx.get("document.getElementById('pair_8849').childNodes[4].innerText");
String wtiPrev = (String) ctx.get("document.getElementById('pair_8849').childNodes[5].innerText");
String wtiChange = (String) ctx.get("document.getElementById('pair_8849').childNodes[8].innerText");
Form op = new Form("Oil Prices", new BoxLayout(BoxLayout.Y_AXIS));
MultiButton wti = new MultiButton("West Texas Intermediate");
Image icon = null;
Image emblem = null;
wti.setEmblem(emblem);
wti.setTextLine2("Current Price: " + wtiLast);
wti.setTextLine3("Previous: " + wtiPrev);
wti.setTextLine4("Change: " + wtiChange);
op.add(wti);
op.show();
}
};
b.setURL("https://sslcomrates.forexprostools.com/index.php?force_lang=1&pairs_ids=8833;8849;954867;8988;8861;8862;&header-text-color=%23FFFFFF&curr-name-color=%230059b0&inner-text-color=%23000000&green-text-color=%232A8215&green-background=%23B7F4C2&red-text-color=%23DC0001&red-background=%23FFE2E2&inner-border-color=%23CBCBCB&border-color=%23cbcbcb&bg1=%23F6F6F6&bg2=%23ffffff&open=show&last_update=show");
}
This method works in the simulator (and gives a "depreciated API" warning), but does not run when I submit my build online after signing. I have imported the parse4cn1 and cn1JSON libraries and have gone through a series of obstacles but I still receive a build error when I submit. I want to start fresh and use an alternative method if one exists. Is there a way that I can rewrite this segment of code without having to use these libraries? Maybe by using the XMLParser class?
The deprecation is for the WebBrowser class. You can use BrowserComponent directly so WebBrowser is redundant in this case.
I used XMLParser for this use case in the past. It should work with HTML as it was originally designed to show HTML.
It might also be possible to port JSoup to Codename One although I'm not sure about the scope of effort involved.
It's very possible that onLoad isn't invoked for a site you don't actually see rendered so the question is what specifically failed on the device?
I need to create form to upload file from client side to server in AX 2012 R3 using X++.
Can some one give me link / example regarding this issue?
I try to search and find that I can use class SysFileStoreManager, but still confused how to use it.
You can find example use of SysFileStoreManager using the Cross-reference Tool. I find it a bit bloated.
You can do this:
static client container getPackedFileClient(FileName _fileNameClient)
{
BinData binData = new BinData();
binData.loadFile(_fileNameClient);
return binData.getData();
}
This is the SysFileStoreManager.getPackedFileClient method, but without the protected keyword.
To save the file:
static server container saveFileToServer(container _packedFile, Filename _filename)
{
#File
BinData b = new BinData();
b.setData(_packedFile);
new FileIOPermission(_filename, #IO_WRITE).assert();
b.saveFile(_filename);
}
This is SysFileStoreManager.copyFileToClient_Client adapted for general use. You can the call the methods in sequence:
saveFileToServer(getPackedFileClient(clienFileName), serverFileName);
The file content is transferred from client to server using a container.
I have been working on a WCF web service, which is used by a mobile app that would send some data to it and save to DB.
One of the test case is that we try to append 2 (or more) records in the app, and the service is called to do a batch insert / update action.
Everything goes fine when I test using localhost, but when we test it using production server, only
the first record is saved, while the other record triggers the error message
Unable to determine a valid ordering for dependent operations...store-generated values.
I have no idea what is the cause and how to solve it. I have done some research and I am quite sure that the related model/DB table has NO circular dependency or self dependency.
Below is a snippet of the web service:
public void submit(List<SubmissionParameter> param){
using (var context = ObjectContextManager.AuditEnabledInstance){
foreach (var item in param){
ReadingSubmission readingSubmission = context.ReadingSubmissions.Where(p => p.ReadingSubmissionUniqueIdentifier == item.Readingsubmissionuniqueidentifier).SingleOrDefault();
if (readingSubmission == null){
readingSubmission = new ReadingSubmission();
context.ReadingSubmissions.AddObject(readingSubmission);
}
readingSubmission.ReadingSubmissionUniqueIdentifier = item.Readingsubmissionuniqueidentifier;
readingSubmission.SystemID = item.Systemid;
readingSubmission.UserID = item.Userid;
foreach (var record in item.Readings){
SystemReading systemReading = context.SystemReadings.Where(p => p.SystemReadingUniqueIdentifier == record.Systemreadinguniqueidentifier).SingleOrDefault();
if (systemReading == null){
systemReading = new SystemReading();
readingSubmission.SystemReadings.Add(systemReading);
}
systemReading.SystemReadingUniqueIdentifier = record.Systemreadinguniqueidentifier;
systemReading.MeasurementID = record.Measurementid;
}
context.SaveChanges();
}
}
}
ReadingSubmission and SystemReading is a 1 to many relation
SubmissionParameter is just a transmission object as the mobile client will send the JSON object to this web service.
I use Telerik Fiddler to post the JSON into this web service for testing, so I am quite sure the problem is not at the mobile client side.
Any help is appreciated! Thanks!
Finally I solve the problem though I am not quite sure why it works.
I move the context.SaveChanges() out of the foreach loop then it all works again for
both localhost and production
Hope it can help someone to save some time
I'm currently working on a system that will export all the nodes from my AX 2009 AOT to individual XPO files, for the purpose of tracking changes in a central version control repository. I'm having a fair amount of luck, but for some reason I cannot get the Forms or Data Sets node to export at all.
This is my current code set:
private void export(str parentNode)
{
TreeNode node, parent;
str folderName;
Set permissions = new Set(Types::Class);
;
folderName = exportBaseDir + parentNode;
permissions.add(new FileIoPermission(folderName, "r"));
permissions.add(new InteropPermission(InteropKind::ClrInterop));
CodeAccessPermission::assertMultiple(permissions);
//Create Filesystem Folder if needed
if (!WinApiServer::pathExists(folderName))
System.IO.Directory::CreateDirectory(folderName);
CodeAccessPermission::revertAssert();
parent = TreeNode::findNode(parentNode);
if (parent)
node = parent.AOTfirstChild();
else
warning(strfmt("Could not parse node: %1", parentNode));
while (node)
{
this.exportNode(node);
node = node.AOTnextSibling();
}
}
When I call export(#"\Forms"); or export(#"\Data Sets"); I get a "Could not parse node" message, meaning the TreeNode::findNode() didn't resolve correctly. Running it on any other node (such as Classes) does not have this issue. This also only happens when it is run in a Batch -- running it with the client (with the CodeAccessPermission parts removed) will export all nodes as expected.
Is there something that would prohibit Forms and Data Sets from being accessed from within a Batch? If so, what can I do to access those nodes?
As far as I can tell it's a server/client issue/bug. The easy solution would be to create this method on your class:
client static TreeNode clientTreeNode(str _path)
{
return TreeNode::findNode(_path);
}
Then in your code, below the parent = TreeNode::findNode(parentNode); line, put:
parent = parent ? parent : YourClassHere::clientTreeNode(parentNode);
And that should solve your issue. You'll have a bit of digging to do in order to find out why it doesn't work on the server tier if you just must know.
I am trying to override the javascript controller node-header.js of components\node-details with the extension module of alfresco share
This is my node-header.get.js
<import resource="classpath:/alfresco/templates/org/alfresco/import/alfresco-util.js">
for (var i=0; i<model.widgets.length; i++)
{
if (model.widgets[i].id == "NodeHeader")
{
if(model.widgets[i].options.nodeRef!=null)
{
var jsNode = new Alfresco.util.Node(model.widgets[i].options.nodeRef);
if(jsNode.hasAspect("custom:intranetFile")){
model.widgets[i].options.showFavourite = false;
model.widgets[i].options.showLikes = false;
}
}
}
}
I am getting this error
Error Message: 05270002 Failed to execute script
'classpath*:webscripts/custom/nodeheader/hidelikesync/node-header.get.js':
05270001 ReferenceError: "Alfresco" is not defined.
(jar:file:/C:/Alfresco/Alfresco42/tomcat/webapps/share/WEB-INF/lib/customshare.jar!/webscripts/custom/nodeheader/hidelikesync/node-header.get.js#1555)
Error lies in this line
var jsNode = new Alfresco.util.Node(model.widgets[i].options.nodeRef);
as Alfresco object is not available how can I get it?
Based on my answer yesterday on the share-extras-devel list:
Your issue is that you are mixing up your web script JS with client-side JavaScript. Alfresco.util.Node is a client-side helper class and is therefore available to client-side JS running in the web browser, but not to your web script code which runs on the server.
If you look at the source of alfresco-util.js, which you are including, you will see that there is a helper class there but it is called AlfrescoUtil.
To get some information on this given node I would suggest that you want to use the static method AlfrescoUtil.getNodeDetails() from that class, e.g.
var jsNode = AlfrescoUtil.getNodeDetails(model.widgets[i].options.nodeRef);
The structure of the jsNode object will be as per the JSON returned by the doclist-v2 webscripts, so you should be able to check for the presence of your custom aspect in the aspects array property.
If you check the source of alfresco-util.js you will see that additional parameters are also supported by getNodeDetails(). It seems to me you can also pass in an optional site name, plus some options if you wish.