cancel
Showing results for 
Search instead for 
Did you mean: 

Package name /Jar for DataDictionaryHelper class

hamd
Champ in-the-making
Champ in-the-making
Hello,
I am using alfresco 4.0.2 enterprise, I found an example webscript for uploading a file, it uses reference of DataDictionaryHelper class but I don't know its package name and its jar file also my IDE (Netbeans 7.2) couldn't able to give me suggestion. Could anyone tell me how can I import DataDictionaryHelper class? My code is


public class UploadWebScript extends DeclarativeWebScript {

   private static Log log = LogFactory.getLog(UploadWebScript.class);
  
   private NodeService nodeService;
   private ContentService contentService;
   private TransactionService transactionService;
   private DataDictionaryHelper dataDictionaryHelper;
   private MimetypeService mimetypeService;
   
    public void setNodeService(NodeService nodeService) {
        this.nodeService = nodeService;
    }
  
   public void setContentService(ContentService contentService) {
      this.contentService = contentService;
   }

   public void setTransactionService(TransactionService transactionService) {
      this.transactionService = transactionService;
   }

   public void setDataDictionaryHelper(DataDictionaryHelper dataDictionaryHelper) {
      this.dataDictionaryHelper = dataDictionaryHelper;
   }
   
    public void setMimetypeService(MimetypeService mimetypeService) {
        this.mimetypeService = mimetypeService;
    }
   
    @Override
    protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
       I18NUtil.setLocale(Locale.ENGLISH);
   Map<String, Object> model = new HashMap<String, Object>();
       UserTransaction tx = transactionService.getUserTransaction(false);
       try {
         tx.begin();
           NodeRef newNode = createNewNode(req);
         tx.commit();
           model.put("newNode", newNode);
       } catch (RollbackException e) {
         log.warn(e);
         status.setCode(500);
         status.setMessage(e.getLocalizedMessage());
         status.setException(e);
         status.setRedirect(true);
      } catch (Exception e) {
         log.warn(e);
         status.setCode(500);
         status.setMessage(e.getLocalizedMessage());
         status.setException(e);
         status.setRedirect(true);
         try {
            tx.rollback();
         } catch (Exception e1) {
            log.error("Transaction rollback failed");
            log.error(e1);
         }
      }
      return model;
    }

   private NodeRef createNewNode(WebScriptRequest req) {
           if (log.isDebugEnabled()) {
         log.debug("Creating new node of type '" + req.getParameter("type") + "' under node " + req.getParameter("uuid"));
      }

        Map<String, String> params = getRequestParametersAsMap(req);
        Map<QName, Serializable> properties = dataDictionaryHelper.convertParametersToProperties(params);
        NodeRef parent = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, req.getParameter("uuid"));
       
        QName contentTypeQname = QName.createQName(YOUR_CUSTOM_NAMESPACE, req.getParameter("type"));

        FormData fd = (FormData) req.parseContent();
        FormField[] fields = fd.getFields();
        for (FormField field : fields) {
           if (field.getIsFile()) {
             String name = field.getFilename();
               properties.put(ContentModel.PROP_NAME, name);
               ChildAssociationRef children = nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS,
                     DataDictionaryHelper.getAssocNameFromFileName(name), contentTypeQname, properties);
               NodeRef newNode = children.getChildRef();
            
              ContentWriter writer = contentService.getWriter(newNode, ContentModel.PROP_CONTENT, true);
              writer.setMimetype(mimetypeService.guessMimetype(name));
              writer.putContent(field.getInputStream());
              return newNode;
         }
        }
        log.warn("Request did not have a file");
        return null;
   }

   private Map<String, String> getRequestParametersAsMap(WebScriptRequest req) {
      Map<String, String> params = new HashMap<String, String>();
      for (String name : req.getParameterNames()) {
         params.put(name, req.getParameter(name));
      }
      return params;
   }
}
2 REPLIES 2

abarisone
Star Contributor
Star Contributor
Hi,
DataDictionaryHelper is just a support class that I use to manage DataDictionary objects.
You can build your own adding this method to make previous code compile:

public static QName getAssocNameFromFileName(String name) {
     // TODO: convert name to ISOwhatever encoding
     return QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name);
}
Regards,
Andrea

hamd
Champ in-the-making
Champ in-the-making
Thanks Andrea!
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.