cancel
Showing results for 
Search instead for 
Did you mean: 

Title is null???

spdaly
Champ in-the-making
Champ in-the-making
I have a webscript that takes a file that is POSTed and creates a new node and places it into a new node.  Some metadata is also passed.  One item is the title of the file.  Here's the script:


      var file = folder.childByNamePath(filename);
      if (file==null) {
         var file = folder.createNode(filename, "{http://www.wearport.com/model/content/1.0}art");
      }
      
      file.properties.content.write(filecontent);
      file.properties.content.encoding = "UTF-8";
      file.properties.content.mimetype = mimetype;
      file.properties.title = title;

The file is written. The encoding and mimetype are correct, but the title remains null. 

I use the node browser and there is a property called title, but it's null!

I'm not sure what I'm doing wrong.
2 REPLIES 2

mikeh
Star Contributor
Star Contributor
You've only posted part of your webscript logic. Where is the "title" variable being populated?

Also, you've declared another "file" variable that's only scoped within the "if" block. Remove the second "var" statement.

Mike

spdaly
Champ in-the-making
Champ in-the-making
Here's the script:


var filename = null;
var filecontent = null;
var path = null;
var mimetype = null;
var title = null;
var author = null;
var s7node  = null;
var libnode = null;
var file = null;

for each (field in formdata.fields)
{
   if (field.name != "file") {
      logger.log("Field: " + field.name + " Value: " + field.value);
   }
  if (field.name == "file" && field.isFile)
  {
    filename = field.filename;
    filecontent = field.content;
  } else if (field.name == "folder") {
     foldernode = field.value;
  } else if (field.name == "path") {
     path = field.value;
  } else if (field.name == "mimetype") {
     mimetype = field.value;
  } else if (field.name == "title") {
     title = field.value;
  } else if (field.name == "author") {
     author = field.value;
  }
}

// ensure mandatory file attributes have been located
if (filename == undefined || filecontent == undefined)
{
  status.code = 400;
  status.message = "Uploaded file cannot be located in request";
  status.redirect = true;
}

logger.log("finding node workspace://SpacesStore/" + path);
var folder = companyhome.childByNamePath(path);

if (folder == null || !folder.isContainer)
{
   status.code = 404;
      status.message = "Path " + path + " not found.";
      status.redirect = true;
} else {
   
   var t = filename.lastIndexOf("\\");
   if (t != -1) {
      filename = filename.substr(t + 1);
   }
   
   try {
      file = folder.createNode(filename, "{http://www.wearport.com/model/content/1.0}art");

      /* manually add titled aspect in order to fix issue with working-copy */
      var scAspectQName = "{http://www.alfresco.org/model/content/1.0}titled";
      var addAspect = actions.create("add-features");
        addAspect.parameters["aspect-name"] = scAspectQName;
      addAspect.execute(file);

      file.properties.content.write(filecontent);
      file.properties.content.encoding = "UTF-8";
      file.properties.content.mimetype = mimetype;
      logger.log("setting title to :" + title);
      file.properties.title = title;

      file.addAspect("cm:referencing");
      
      logger.log("attempting transformation…");
       var libFolder = folder.childByNamePath("Library");
       libnode = file.transformImage("image/png", "-resize x80", libFolder);
       if (libnode != null) {
          logger.log("transformation worked");
           libnode.name = "X80"+file.name+".png";
           libnode.properties.content.mimetype = "image/png";
           file.createAssociation(libnode, "cm:references");
           file.addAspect("{http://www.wearport.com/model/content/1.0}library");
           logger.log("Saving Lib Node: " + libnode.name);
           libnode.save();
       }
      
       s7node = file.transformImage("image/png", "-resize 1000x1000", libFolder);
       if (s7node != null) {
          logger.log("s7 transformation worked");
           s7node.name = "X1000"+file.name+".png";
           s7node.properties.content.mimetype = "image/png";
           file.createAssociation(s7node, "cm:references");
           s7node.save();
       }
         
       logger.log("saving uploaded file");
      file.save();
      
      model.msg = 'ok';
      model.success = true;
   } catch(e) {
      model.success = false;
      logger.log(e.message);
      if (e.message.indexOf('FileExistsException') != -1) {
         model.msg = 'duplicate';
      } else {
         model.msg = 'generror';
      }
   }
}

and the sys.out:

Sep 12, 2008 12:42:14 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 20678 ms
12:43:18,167 User:admin DEBUG [repo.jscript.RhinoScriptProcessor] Imports resolved, adding resource '_root
12:43:18,274 User:admin DEBUG [repo.jscript.ScriptLogger] Field: serverGroup Value: http://localhost:8080/alfresco/service/wearport/uploadNew
12:43:18,274 User:admin DEBUG [repo.jscript.ScriptLogger] Field: path Value: Wearport/Wearport/Art
12:43:18,274 User:admin DEBUG [repo.jscript.ScriptLogger] Field: mimetype Value: image/gif
12:43:18,274 User:admin DEBUG [repo.jscript.ScriptLogger] Field: title Value: Logo
12:43:18,274 User:admin DEBUG [repo.jscript.ScriptLogger] Field: desc Value: Logo
12:43:18,275 User:admin DEBUG [repo.jscript.ScriptLogger] Field: author Value:
12:43:18,275 User:admin DEBUG [repo.jscript.ScriptLogger] Field: filename Value:
12:43:18,277 User:admin DEBUG [repo.jscript.ScriptLogger] finding node workspace://SpacesStore/Wearport/Wearport/Art
12:43:18,278 User:admin DEBUG [repo.jscript.ScriptNode] Executing xpath: *[@cm:name=$cm:name0]/*[@cm:name=$cm:name1]/*[@cm:name=$cm:name2]
12:43:18,278 User:admin DEBUG [repo.jscript.ScriptNode]  [{http://www.alfresco.org/model/content/1.0}name0]=Wearport
12:43:18,278 User:admin DEBUG [repo.jscript.ScriptNode]  [{http://www.alfresco.org/model/content/1.0}name1]=Wearport
12:43:18,278 User:admin DEBUG [repo.jscript.ScriptNode]  [{http://www.alfresco.org/model/content/1.0}name2]=Art
12:43:18,351 User:admin DEBUG [repo.jscript.ScriptLogger] setting title to :Logo
12:43:18,357 User:admin DEBUG [repo.jscript.ScriptLogger] attempting transformation…
12:43:18,357 User:admin DEBUG [repo.jscript.ScriptNode] Executing xpath: *[@cm:name=$cm:name0]
12:43:18,357 User:admin DEBUG [repo.jscript.ScriptNode]  [{http://www.alfresco.org/model/content/1.0}name0]=Library
12:43:18,703 User:admin DEBUG [repo.jscript.ScriptLogger] transformation worked
12:43:18,755 User:admin DEBUG [repo.jscript.ScriptLogger] Saving Lib Node: X80logo.gif.png
12:43:19,192 User:admin DEBUG [repo.jscript.ScriptLogger] s7 transformation worked
12:43:19,231 User:admin DEBUG [repo.jscript.ScriptLogger] saving uploaded file
12:43:19,234 User:admin DEBUG [repo.jscript.RhinoScriptProcessor] Time to execute script: 1067ms

Thanks!