среда, 27 декабря 2017 г.

Stemming Apache Lucene example Russian language

Example of Stemming Apache Lucene - Russian language:


String querystr = "Проводнику большие";

Analyzer analyzer = new RussianAnalyzer(Version.LUCENE_40);

Directory index = new RAMDirectory();

IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer);

IndexWriter w = new IndexWriter(index, config);
addDoc(w, "Проводник большой", "193398817");
addDoc(w, "Проводнику большому", "55320055Z");
addDoc(w, "Проводные большие", "55063554A");
addDoc(w, "Большие проводники", "9900333X");
w.close();

Query q = new QueryParser(Version.LUCENE_40, "title", analyzer).parse(querystr);

int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(index);
IndexSearcher searcher = new IndexSearcher(reader);
TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
searcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;

System.out.println("Found " + hits.length + " hits.");
for (int i = 0; i < hits.length; ++i) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println((i + 1) + ". " + d.get("isbn") + "\t" + d.get("title"));
}

reader.close();

вторник, 12 декабря 2017 г.

How to call SAP BPM OData service api from jQuery ajax

How to call SAP BPM OData service api from jQuery ajax.

Call with "GET" method:
If you want to call BPM OData service via http "GET" method, then you just call it via jQuery $.ajax.

Call with "POST" method:
If you want to call BPM OData service via http "POST" method, then first you have to call some BPM OData service with "GET" method with http header 'x-csrf-token' with value 'Fetch' to get token. Then you have to call BPM OData service with "POST" method and you have to set 'x-csrf-token' header which you recieved in previous step.

Example:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<div class="MyTest">Hello</div>
<div class="result1">result1</div>
<div class="result2">result2</div>

<script type="text/javascript">

$.ajax({
    url: "http://<server>:<port>/bpmodata/processes.svc/ProcessCollection('<bpm process id>')?$format=json",
    headers: {     
        'x-csrf-token':'Fetch',     
    },
    method: 'GET',
    success: function(data, textStatus, request){
var myToken = request.getResponseHeader('x-csrf-token');                
        $(".result1").html(myToken);

        $.ajax({
            url: "http://<server>:<port>/bpmodata/processes.svc/Cancel?InstanceId='<bpm process id>'&$format=json",
            headers: {     
                'x-csrf-token': myToken,     
            },
            method: 'POST',
            success: function(data, textStatus, request){                
                $(".result2").html('completed');
           },
           error: function (request, textStatus, errorThrown) {
                alert('Error');
           } 
        });
     
   },
   error: function (request, textStatus, errorThrown) {
        alert('Error' + request.getResponseHeader('x-csrf-token'));
   }

 
  });

</script>

</body>
</html>

понедельник, 20 ноября 2017 г.

JDBC get Connection MySql MS SQL

public static Connection getConnection() {

  //MySql
Class.forName("com.mysql.jdbc.Driver");

  //MS SQL
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

String url = PortalHelper.getAppProperties("DATABASE_URL");
String name = "JDBC_USER_NAME";
String password = "JDBC_USER_PASSWORD";

return DriverManager.getConnection(url, name, password);
}

четверг, 25 августа 2016 г.

Make JPA Entity with @OneToMany and @ManyToOne mapping tags

Problem:
Your need to make JPA Entity with @OneToMany and @ManyToOne mapping tags.

Solution:
You have tables like this:

Table "Requests":
Field Type
ID Integer
STEP_ID Integer

Table "Steps":
Field Type
ID Integer
REQUEST_ID Integer

Table "Requests" should have in field "Step_Id" many rows from table "Steps", and table "Steps" should have in field "Requst_Id" one row from "Requests" table.

Make JPA Entities like this:

@Entity
@Table(name="REQUESTS")
public class Requests implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;

@OneToMany(mappedBy="request", fetch=FetchType.EAGER)
private Set<Steps> steps = new HashSet<Steps>();


public Requests() {
}

public long getId() {
return this.id;
}

public void setId(long id) {
this.id = id;
}

public void setSteps(Set<Steps> history) {
this.steps = steps ;
}

public Set<Steps> getSteps() {
return steps;
}
}

@Entity
@Table(name="STEPS")
public class Steps implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;

@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch=FetchType.EAGER)
@JoinColumn(name = "REQUEST_ID")
private EoRequestsEntity request;

public Steps() {
}

public int getId() {
return this.id;
}

public void setRequest(Requests request) {
this.request = request;
}

public EoRequestsEntity getRequest() {
return request;
}

}


Tags "cascade" and "fetch" is required!

That's all!

среда, 24 августа 2016 г.

How to create iView for sap portal web module application

Problem:
How to create iView for sap portal web module application

Solution:

  1. Create URL iView and set link to your web module application. If you do not know thar, you can run it in your Netweaver Developer Studio: right hand mouse click on development component, choose Run on Server - choose your server and run it. You will see url in browser.
  2. In iView properties set property Fetch Mode - Server Side.



пятница, 12 августа 2016 г.

Check if your TLD is valid against its scheme

Problem:
You have an error:
Caused by: com.sap.engine.services.servlets_jsp.jspparser_api.exception.JspParseException: Error in parsing the taglib tag in the JSP page. Cannot resolve URI: [http://java.s.com/jsf/html]. Possible reason - validation failed. Check if your TLD is valid against its scheme. 


Solution:
Put in your ear (Enterprise Application) development component in file ""META-INF/application-j2ee-engine.xml"" that code:

 <application-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="application-j2ee-engine.xsd"> 
    <reference reference-type="weak">
    <reference-target target-type="library" provider-name="sap.com">
       tc~ui~faces
    </reference-target>
    </reference>
  </application-j2ee-engine>

End everything works!

вторник, 5 июля 2016 г.

NWDS prompt for create activity in NWDI when editing some file

To prompt for create activity in NWDI when editing some file in NWDS you should go to Window -> Preference -> Development Infrastructure -> Design Time Repository -> Dialog Settings. In that window choose prompt.

четверг, 8 октября 2015 г.

Logging and Tracing Web Service Call on SAP NetWeaver Portal

You want to see request trace whan web service was called.

You should:

  • Go to /NWA -> Log Configuration
  • Switch to Tracing Locations view
  • go to locations:

com.sap.engine.services.httpserver.HttpTraceRequest.traceHeaders
com.sap.engine.services.httpserver.HttpTraceRequest.traceRaw
com.sap.engine.services.httpserver.HttpTraceResponse.traceHeaders
com.sap.engine.services.httpserver.HttpTraceResponse.traceRaw
  • Set debug mode to all of them