cancel
Showing results for 
Search instead for 
Did you mean: 

Can we create custom attributes, without server restart

prateekgoyal
Champ in-the-making
Champ in-the-making
Hello All,
I want to know that is it possible to create custom attributes in alfresco without restarting the alfresco server.
If yes then how can we do that.

Thanks.
20 REPLIES 20

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
ContentModel.PROP_MODEL_ACTIVE needs to be set. You can do this via api.

prateekgoyal
Champ in-the-making
Champ in-the-making
Hi,
Can you please tell me how to do this sing web service API. Actually i searched on the net, all the methods given are done using other alfresco api's and i was using web service api.

Thanks,

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
you can use web service api http://wiki.alfresco.com/wiki/IngresTutorial_Alfresco_Web_Service_API_for_Java

so when you create your document ( model) set property that I have give to you. This should do the trick.

prateekgoyal
Champ in-the-making
Champ in-the-making
Hi,
actually i have tried that,in Constants class in web service api i didnt find any property like PROP_MODEL_ACTIVE.
So that is the problem with me.

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
can you send me your code?

prateekgoyal
Champ in-the-making
Champ in-the-making
Here is the code that i'm using.
In this if the file already exist in the path mentioned then this code will first delete that file and upload the new one otherwise creates a new file onto the path mentioned.

      
      FileInputStream fis =null;
      RepositoryServiceSoapBindingStub repositoryService =null;
      ContentServiceSoapBindingStub contentService =null;
      AuthoringServiceSoapBindingStub authoringService = null;
      try   {
         Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");         
         ParentReference companyHomeParent = new ParentReference(storeRef, null, "/app:company_home/app:dictionary/app:models" , Constants.ASSOC_CONTAINS, null);
         repositoryService =WebServiceFactory.getRepositoryService();
         contentService =WebServiceFactory.getContentService();   
         authoringService = WebServiceFactory.getAuthoringService();
         Reference contentReference= null;
         String ModelXmlFile = Path + FileName;
         File modelFile = new File(ModelXmlFile);
         NamedValue[] contentProps = new NamedValue[2];
         NamedValue[] titledProps = new NamedValue[2];
         
         CML cml = null;
         Query query = null;
         fis= new FileInputStream(ModelXmlFile);
         byte[] bytes = ContentUtils.convertToByteArray(fis);
         ContentFormat format = new ContentFormat("text/xml", "UTF-8");
         
         
         companyHomeParent.setChildName("{http://www.alfresco.org/model/content/1.0}" + FileName);
         
         contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, FileName);
         //contentProps[1] = Utils.createNamedValue(ContentModel.PROP_MODEL_ACTIVE,"YES");
         titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, FileName);
         titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, "Sample description.");   
         
         CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");
         query = new Query(Constants.QUERY_LANG_LUCENE, "PATH:\"/app:company_home/app:dictionary/app:models/cm:" + ISO9075.encode(FileName) + "\"");
         
         ResultSet rs =repositoryService.query(storeRef, query, false).getResultSet();
         if(rs.getTotalRowCount() > 0) {
            ResultSetRow[] rsRows = rs.getRows();
            contentReference = new Reference(storeRef, rsRows[0].getNode().getId(), null);
            System.out.println("Removing file " + FileName); //show file name
            //Reference reference = new Reference(storeRef, rsRows[0].getNode().getId(), null);
            cml = new CML();
            Predicate predicate = new Predicate(new Reference[]{contentReference}, null, null);
            CMLDelete delete = new CMLDelete(predicate);
            cml.setDelete(new CMLDelete[] {delete});         
            repositoryService.update(cml);
            CMLCreate create = new CMLCreate("1", companyHomeParent, companyHomeParent.getUuid(), Constants.ASSOC_CONTAINS, null, Constants.PROP_CONTENT, contentProps);
            /*NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants,newname)};
            create.setProperty(properties);*/
            cml = new CML();
            cml.setCreate(new CMLCreate[] {create});
            cml.setAddAspect(new CMLAddAspect[] {addAspect});            
            UpdateResult[] result = repositoryService.update(cml);
            Reference content = result[0].getDestination();            
            contentService.write(content,Constants.PROP_CONTENT , bytes, format);
            
         }
         else{
            CMLCreate create = new CMLCreate("1", companyHomeParent, companyHomeParent.getUuid(), Constants.ASSOC_CONTAINS, null, Constants.PROP_CONTENT, contentProps);            
            cml = new CML();
            cml.setCreate(new CMLCreate[] {create});
            cml.setAddAspect(new CMLAddAspect[] {addAspect});            
            UpdateResult[] result = repositoryService.update(cml);
            Reference content = result[0].getDestination();            
            contentService.write(content,Constants.PROP_CONTENT , bytes, format);
            
         }
         
         
      }catch(FileNotFoundException fnf) {
         System.err.println("Exception is" +fnf);
      }catch(RepositoryFault rf) {
         System.err.println("Exception is" +rf);
      }catch(AxisFault af) {
         System.err.println("Exception is" +af);
      }catch (Exception e) {
         System.err.println("Exception is" +e);
      }catch(OutOfMemoryError ome){
         System.err.println("Exception is" +ome);
      }
   

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
have you tried /contentProps[1] = Utils.createNamedValue(ContentModel.PROP_MODEL_ACTIVE, true);

prateekgoyal
Champ in-the-making
Champ in-the-making
yes, it is giving the error as "ContentModel.PROP_MODEL_ACTIVE cannot be resolved"

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
also contentmode.prop… is actually {http://www.alfresco.org/model/content/1.0}modelActive

prateekgoyal
Champ in-the-making
Champ in-the-making
Actually "Utils.createNamedValue()" accepts string value as parameters so i cannot supply ""{http://www.alfresco.org/model/content/1.0}modelActive',true " to this function.