alfresco 4.2e中自定义属性方面的null值

时间:2014-12-31 08:34:13

标签: java alfresco

我正在尝试使用 Alfresco 4.2e java 中插入带有自定义属性的文档。现在插入的值没有任何错误,但是未设置自定义属性的值,它显示为null。

这是我的代码:

    Map<String, String> props = new HashMap<String, String>();
    props.put(PropertyIds.NAME, newDocName);
    props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:kb:referencable");
    props.put("kb:documentRef", "123");
    props.put("kb:documentID", "1234");
    String content = "sample=================";
    byte[] buf = null;
    try {
        buf = content.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    ByteArrayInputStream input = new ByteArrayInputStream(buf);
    ContentStream contentStream = session.getObjectFactory()
            .createContentStream(newDocName, buf.length,
                    "text/plain; charset=UTF-8", input);
    target.createDocument(props, contentStream, VersioningState.MAJOR);

Serach查询:

    String query = "SELECT * FROM kb:referencable ";
    ItemIterable<QueryResult> queryResult = session.query(query, false);
    for (QueryResult item : queryResult) {
         System.out.println("item="+item.getProperties());

    }

以下是搜索输出:

item=[Property [id=kb:documentRef, display Name=KB Reference, local name=documentRef, query name=kb:documentRef, values=[]][extensions=null], Property [id=cmis:objectTypeId, display Name=Object Type Id, local name=objectTypeId, query name=cmis:objectTypeId, values=[cmis:document]][extensions=null], Property [id=cmis:lastModifiedBy, display Name=Last Modified By, local name=lastModifiedBy, query name=cmis:lastModifiedBy, values=[admin]][extensions=null], Property [id=cmis:name, display Name=Name, local name=name, query name=cmis:name, values=[chemistryTest1.txt]][extensions=null], Property [id=cmis:createdBy, display Name=Created by, local name=createdBy, query name=cmis:createdBy, values=[admin]][extensions=null], Property [id=kb:documentID, display Name=kb:documentID, local name=documentID, query name=kb:documentID, values=[]][extensions=null], Property [id=cmis:objectId, display Name=Object Id, local name=objectId, query name=cmis:objectId, values=[149666ab-5745-4365-b63e-c26cb6f4f6cc;1.0]][extensions=null], Property [id=cmis:creationDate, display Name=Creation Date, local name=creationDate, query name=cmis:creationDate, values=[java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+05:30",offset=19800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=2015,MONTH=0,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=1,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=9,MINUTE=32,SECOND=59,MILLISECOND=725,ZONE_OFFSET=?,DST_OFFSET=?]]][extensions=null], Property [id=cmis:changeToken, display Name=Change token, local name=changeToken, query name=cmis:changeToken, values=[]][extensions=null], Property [id=cmis:secondaryObjectTypeIds, display Name=Secondary Object Type Ids, local name=secondaryObjectTypeIds, query name=cmis:secondaryObjectTypeIds, values=[P:kb:referencable, P:cm:titled, P:cm:author, P:sys:localized]][extensions=null], Property [id=cmis:baseTypeId, display Name=Base Type Id, local name=baseTypeId, query name=cmis:baseTypeId, values=[cmis:document]][extensions=null], Property [id=alfcmis:nodeRef, display Name=Alfresco Node Ref, local name=nodeRef, query name=alfcmis:nodeRef, values=[workspace://SpacesStore/149666ab-5745-4365-b63e-c26cb6f4f6cc]][extensions=null], Property [id=cmis:description, display Name=Description, local name=description, query name=cmis:description, values=[]][extensions=null], Property [id=cmis:lastModificationDate, display Name=Last Modified Date, local name=lastModificationDate, query name=cmis:lastModificationDate, values=[java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+05:30",offset=19800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=2015,MONTH=0,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=1,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=9,MINUTE=32,SECOND=59,MILLISECOND=725,ZONE_OFFSET=?,DST_OFFSET=?]]][extensions=null]]

kb:documentRef和kb:documentID(custom property)的值为null。

1 个答案:

答案 0 :(得分:1)

老实说,我不知道kb:documentRef是否被解析为简写,但传递的props地图必须是这种类型:

Map<QName,Serializable> props = new Map<QName,Serializable>();

然后假设模型中的命名空间为http://www.custommodel.com/kb/1.0,您应该这样做:

props.put(new QName("http://www.custommodel.com/kb/1.0","documentRef"), "123");
props.put(new QName("http://www.custommodel.com/kb/1.0","documentID"), "1234");

或者,更好的是,您可以编写便捷的界面:

public interface MyModel {
   KB_DOCUMENT_REF = new QName("http://www.custommodel.com/kb/1.0","documentRef");
}

然后,更清楚:

props.put(MyModel.KB_DOCUMENT_REF, "123");