Java Based Apps on SAP Cloud_4_J
SAP JAM
ESPM中,使用master branch。启用SAP JAM服务

进入管理员界面,点击外部应用程序

点击添加应用程序,创建ESPM应用
创建完后,点击管理记录类型,添加记录类型

添加Product 记录类型
外部类型:
https://espmxxxxxxxtrial.hanatrial.ondemand.com/espm-cloud-web/espm.svc/$metadata#Products
注释URL:
https://espmxxxxxxxtrial.hanatrial.ondemand.com/espm-cloud-web/webshop/reviews_annotations.xml

同样添加CustomerReviews记录类型
外部类型:
https://espmxxxxxxxtrial.hanatrial.ondemand.com/espm-cloud-web/espm.svc/$metadata#CustomerReviews
注释URL:
https://espmxxxxxxxtrial.hanatrial.ondemand.com/espm-cloud-web/webshop/reviews_annotations.xml
在CustomerReviews记录类型中,添加2个过滤器,分别过滤Rating eq 5和Rating eq 1

在产品设置-群组模板中,我们可以上传模板,模板下载地址https://sapjamsamplecode.github.io/GroupTemplates/ESPM_Reviews-Products.zip

在主页的业务记录,可以看到ESPM应用

点击进去可以查看详细

针对单条记录,我们可以创建群组,模板选择上传的 ESPM Review-Product 模块

查看创建的群组,点击面板上的编辑,可以编辑组件内容

删除原来的小部件,点击添加小部件按钮,可以添加相关业务记录的内容,编辑完成后,点击发布,更新应用

点击相关的条目,可以再次添加评论

文档管理
HCP通过CMIS服务来管理文档

文档管理步骤
1 Create a new repository:创建一个RepositoryOptions,设置唯一的Name与Key,创建InitialContext并调用
lookup("java:comp/env/EcmService")
方法创建EcmService
RepositoryOptions options = new RepositoryOptions();
options.setUniqueName("com.foo.MyRepository");
options.setRepositoryKey("my_super_secret_key_123"); // (min. 10 chars)
options.setVisibility(Visibility.PROTECTED);
//optionally enable virus scanning on upload: options.setVirusScannerEnabled(true);
InitialContext ctx = new InitialContext();
EcmService ecmService = (EcmService) ctx.lookup("java:comp/env/EcmService");
ecmService.createRepository(options);
2 Connect and fetch the root folder:通过Name与Key连到EcmService,可以获取RootFolder
openCmisSession = ecmService.connect(”com.foo.MyRepository”, ”my_super_secret_key_123”);
Folder root = openCmisSession.getRootFolder();
3 Get all children of root folder:通过root folder可以获取子文件夹
ItemIterable<CmisObject> children = root.getChildren();
for (CmisObject o : children) { ... }
4 Create a new document:创建新的文档,定义文档的类型与名称,再定义内容,文档内容转成InputStream
// define manadatory properties
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
properties.put(PropertyIds.NAME, "HelloWorld.txt");
// define the content
byte[] helloContent = "Hello World!".getBytes("UTF-8");
InputStream stream = new ByteArrayInputStream(helloContent);
ContentStream contentStream = openCmisSession.getObjectFactory().createContentStream("HelloWorld.txt",
helloContent.length, "text/plain; charset=UTF-8", stream);
// create the document below the root node
root.createDocument(properties, contentStream, VersioningState.NONE);
在SalesOrderProcessor.java文件的getSalesOrderById方法调用InvoiceBuilder生成PDF文档
// if the sales order are fetched successfully, generate the pdf report data.
try {
if (CMISSessionHelper.getInstance().getSession() != null) {
InvoiceBuilder builder = new InvoiceBuilder();
String reportPath = builder.generateInvoice(soiList);
updateSalesOrderHeader(reportPath, soiList, em);
}
ESPM中的文档管理
InvoiceBuilder中,通过Folder root = CMISSessionHelper.getInstance().getSession().getRootFolder();
调用公共类CMISSessionHelper中的方法获取API,CMISSessionHelper公共方法中,定义了获取文档的Session等内容。
网页访问时,点击下载按钮调用CmisRead这个Servlet,首先在init方法中获取CmisSession
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
openCmisSession = CMISSessionHelper.getInstance().getSession();
} catch (Exception | NoClassDefFoundError e1) {
LOGGER.error(e1.getMessage());
}
}
在doGet方法中,获取文档流,并输出
final String objectId = request.getParameter("objectId");
try {
if (openCmisSession != null) {
Document doc = (Document) openCmisSession.getObject(objectId);
ContentStream content = doc.getContentStream();
String type = content.getMimeType();
String name = content.getFileName();
int length = (int) content.getLength();
InputStream stream = content.getStream();
response.setContentType(type);
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + name);
response.setContentLength(length);
ioCopy(stream, response.getOutputStream());
} else {
response.setStatus(501);
}
} catch (Exception exception) {
exception.printStackTrace();
}
Twitter APP
CheckOut Twitter Branch
TwitterUpdateWs.java文件中,修改final String statusMessage = "@openSAP test connection";
,TwitterUpdate.java文件中,记录Key与Secret。
static String consumerKeyStr = twitterDetails.get("consumerApplicationKey");
static String consumerSecretStr = twitterDetails.get("consumerApplicationSecret");
config.properities文件中,确定DestinationName
#Twitter Application Keys
OAuthDestinationName=twitterOauth
apps.twitter
登陆https://apps.twitter.com,创建APP,其中Callback URL 填写webshop的URL,Permission改为Read, write, and direct messages,获取Consumer Key (API Key)与Consumer Secret (API Secret)

HCP Destination
HCP中创建链接,名称为OAuthDestinationName的内容,添加属性,key为代码中consumerApplicationKey与consumerApplicationSecret,value为Twitter API中的值

测试APP
登陆https://espmc5228335trial.hanatrial.ondemand.com/espm-cloud-web,首次登陆会有Twitter授权页面

创建Order并CheckOut
查看Twitter发布的消息,即为statusMessage中的内容
