Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project restructuration + Logging and Docker Enabling. #8

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions objectmorph-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,35 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.3.5</version>
<configuration>
<imageName>objectmorph-app-image:${project.parent.version}</imageName>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies -->
<!--
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.3.5</version>
<type>pom</type>
<scope>import</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.3.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.mohamedennahdi.objectmorph.objectmorph;
package com.github.mohamedennahdi.objectmorph.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.github.mohamedennahdi.objectmorph.objectmorph.controller;
package com.github.mohamedennahdi.objectmorph.app.controller;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

import org.springframework.http.HttpStatus;
Expand All @@ -11,9 +8,10 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.mohamedennahdi.objectmorph.objectmorph.service.ObjectmorphService;
import com.github.mohamedennahdi.objectmorph.app.service.ObjectmorphService;

import io.swagger.v3.oas.annotations.Parameter;

Expand All @@ -38,20 +36,16 @@ public ResponseEntity<String> test(List<String> files) {
}

@GetMapping( value = "/html" )
public ResponseEntity<String> html(@Parameter(name = "sourceCode", description = "Source Code", example = "class SourceCode { int attribute1; int attribute2; SourceCode(){} public int getAttribute1() { return attribute1;}}") String[] sourceCode) {
String html = "";
public ResponseEntity<String> html(@Parameter(name = "sourceCode", description = "Source Code", example = "class SourceCode { int attribute1; int attribute2; SourceCode(){} public int getAttribute1() { return attribute1;}}")
@RequestParam("sourceCode") String[] sourceCode) {
try {
String html = "";
html = objectmorphService.generateHTML(sourceCode);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
return new ResponseEntity<>(html, HttpStatus.OK);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(html, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.mohamedennahdi.objectmorph.objectmorph.logic;
package com.github.mohamedennahdi.objectmorph.app.logic;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.mohamedennahdi.objectmorph.objectmorph.service;
package com.github.mohamedennahdi.objectmorph.app.service;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -15,8 +15,11 @@
import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Service;

import com.github.mohamedennahdi.objectmorph.objectmorph.logic.ObjectmorphSingleton;
import com.github.mohamedennahdi.objectmorph.app.logic.ObjectmorphSingleton;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class ObjectmorphService {
ObjectmorphSingleton objectmorphLogic;
Expand All @@ -31,22 +34,20 @@ public String generateHTML(String[] sourceCodes) throws IOException, URISyntaxEx
String patternString = "(?<=class ).*?(?=\\s)";
Pattern pattern = Pattern.compile(patternString);

String path = System.getProperty("user.home");
for (String sourceCode: sourceCodes) {
Matcher matcher = pattern.matcher(sourceCode);
if (matcher.find()) {
System.out.println(matcher.group());
String fileName = matcher.group() + ".java";
log.info("Filename: " + fileName);
File file = Files.createFile(Paths.get(path + File.separator + fileName)).toFile();
FileUtils.writeStringToFile(file, sourceCode, StandardCharsets.UTF_8);
files.add(file);
}

File file = Files.createFile(Paths.get(matcher.group() + ".java")).toFile();
FileUtils.writeStringToFile(file, sourceCode, StandardCharsets.UTF_8);
files.add(file);
}


return objectmorphLogic.getHtmlGenerator(files.toArray(new File[0])).generateFullHTML();
} catch (FileNotFoundException e) {
throw e;
} catch (URISyntaxException e) {
} catch (Exception e) {
throw e;
} finally {
for (File file : files) {
Expand Down
12 changes: 11 additions & 1 deletion objectmorph-app/src/main/resources/applications.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
spring:
application:
name: "objectmorph-app"
name: "objectmorph-app"
logging:
level:
root: DEBUG
com:
github:
objectmorph: WARN
file.name: logs/objectmorph-app.log
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n"
file: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n"