Skip to content

Commit

Permalink
Merge pull request #90 from nimble-platform/staging
Browse files Browse the repository at this point in the history
Pull Request for Release 17.0.5
  • Loading branch information
dogukan10 authored May 12, 2020
2 parents a03af1e + 94980b0 commit e4a9df0
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 1 deletion.
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,26 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>eu.nimble.service.bp.util.GenerateSourceUtil</mainClass>
<arguments>
<argument>${project.basedir}/src/main/java/eu/nimble/service/bp/model/hyperjaxb</argument>
<argument></argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.09.16 at 03:08:56 PM EET
// Generated on: 2020.05.12 at 07:17:05 PM EET
//


package eu.nimble.service.bp.model.hyperjaxb;

import javax.persistence.OrderBy;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
Expand Down Expand Up @@ -592,6 +593,7 @@ public void setHjid(Long value) {
CascadeType.ALL
})
@JoinColumn(name = "PROCESS_INSTANCE_IDS_ITEMS_P_0")
@OrderBy("hjid")
public List<ProcessInstanceGroupDAO.ProcessInstanceGroupDAOProcessInstanceIDsItem> getProcessInstanceIDsItems() {
if (this.processInstanceIDsItems == null) {
this.processInstanceIDsItems = new ArrayList<ProcessInstanceGroupDAO.ProcessInstanceGroupDAOProcessInstanceIDsItem>();
Expand Down
150 changes: 150 additions & 0 deletions src/main/java/eu/nimble/service/bp/util/GenerateSourceUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package eu.nimble.service.bp.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GenerateSourceUtil {

private final Logger logger = LoggerFactory.getLogger(this.getClass());
final private String regex_process_instance_group_dao = "public class ProcessInstanceGroupDAO";
final private String regex_process_instance_groups_process_ids = "public List<ProcessInstanceGroupDAO.ProcessInstanceGroupDAOProcessInstanceIDsItem> getProcessInstanceIDsItems()";
final private String regex_import_statement = "import";

final private String import_statement_for_order_by = "import javax.persistence.OrderBy;\n";
final private String order_by_annotation = "@OrderBy(\"hjid\")\n ";

public static void main(String [] args){
GenerateSourceUtil generateSourceUtil = new GenerateSourceUtil();
generateSourceUtil.postProcessORMAnnotations(args[0]);
}

public void postProcessORMAnnotations(String path){
logger.debug("Started to process ORM annotations");
File directory = new File(path);
searchDirectory(directory);
logger.debug("Process ORM annotations successfully");
}

public void searchDirectory(File directory){
File[] filesAndDirs = directory.listFiles();
for(File file : filesAndDirs){
if(file.isFile()){
String fileContent = getFileContent(file);
FileUpdate fileUpdate = new FileUpdate();
fileUpdate.setContent(fileContent);

addOrderByAnnotation(fileUpdate);

updateFile(file, fileUpdate);
}
else {
searchDirectory(file);
}
}
}

private void addOrderByAnnotation(FileUpdate fileUpdate) {
String fileContent = fileUpdate.getContent();
Pattern p = Pattern.compile(regex_process_instance_group_dao,Pattern.DOTALL);
Matcher m = p.matcher(fileContent);
if(m.find()){
fileContent = fileContent.replace(regex_process_instance_groups_process_ids, order_by_annotation+regex_process_instance_groups_process_ids);
fileContent = fileContent.replaceFirst(regex_import_statement,import_statement_for_order_by+regex_import_statement);
fileUpdate.setContent(fileContent);
fileUpdate.setFileUpdated(true);
}
}

private void updateFile(File file, FileUpdate fileUpdate) {
if(!fileUpdate.isFileUpdated()) {
return;
}

try {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(fileUpdate.getContent());

BufferedWriter bwr = new BufferedWriter(new FileWriter(file));

//write contents of StringBuffer to the file
bwr.write(stringBuffer.toString());

//flush the stream
bwr.flush();

//close the stream
bwr.close();

} catch(IOException e) {
throw new RuntimeException("Failed to update file", e);
}
}

private String getFileContent(File file) {
FileInputStream fileStream = null;
BufferedReader br = null;
InputStreamReader inputStreamReader = null;
try {
StringBuffer text = new StringBuffer();
fileStream = new FileInputStream(file);
inputStreamReader = new InputStreamReader(fileStream);
br = new BufferedReader(inputStreamReader);
for (String line; (line = br.readLine()) != null; )
text.append(line + System.lineSeparator());

String fileText = text.toString();
return fileText;

} catch (IOException e) {
throw new RuntimeException("Failed to get file content", e);
} finally {
if(fileStream != null){
try {
fileStream.close();
} catch (IOException e) {
logger.warn("Failed to close file stream: ",e);
}
}
if(br != null){
try {
br.close();
} catch (IOException e) {
logger.warn("Failed to close buffered reader: ",e);
}
}
if(inputStreamReader != null){
try {
inputStreamReader.close();
} catch (IOException e) {
logger.warn("Failed to close input stream reader: ",e);
}
}
}
}

static class FileUpdate {
private boolean fileUpdated = false;
private String content;

public boolean isFileUpdated() {
return fileUpdated;
}

public void setFileUpdated(boolean fileUpdated) {
this.fileUpdated = fileUpdated;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}
}

}

0 comments on commit e4a9df0

Please sign in to comment.