ajout dans isValid de la vérification que les Property sont valid + HtmlRenerator terminé
This commit is contained in:
@@ -1 +1,38 @@
|
||||
<!DOCTYPE html><html><head><title>Cartailor</title></head>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Cartailor</title>
|
||||
<style>
|
||||
table{border-collapse: collapse;}
|
||||
th,td{border: 1px solid rgb(160 160 160);padding: 8px 10px;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Interior</th>
|
||||
<th>IS</th>
|
||||
<th>2500 €</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Transmission</th>
|
||||
<th>TSF7</th>
|
||||
<th>15000 €</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Exterior</th>
|
||||
<th>XS</th>
|
||||
<th>10000 €</th>
|
||||
<th>color : red</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Engine</th>
|
||||
<th>EG210</th>
|
||||
<th>25000 €</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="2">Total Price : </th>
|
||||
<th>52500 € </th>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -8,6 +8,7 @@ import src.fr.api.Part;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfigurationImpl implements Configuration {
|
||||
@@ -23,6 +24,14 @@ public class ConfigurationImpl implements Configuration {
|
||||
public boolean isValid() {
|
||||
boolean test = true;
|
||||
for(Part pt1: selectedParts){
|
||||
for(String pr: pt1.getPropertyNames()){
|
||||
Optional<String> prOptional = pt1.getProperty(pr);
|
||||
if(!prOptional.isEmpty()){
|
||||
test = ((PartImpl)pt1).isValidProperty(pr);
|
||||
}
|
||||
else test = false;
|
||||
}
|
||||
|
||||
boolean test_Requirement = true;
|
||||
boolean test_Incompabilities = true;
|
||||
System.out.println("name : " + pt1.getType().getName());
|
||||
|
||||
@@ -4,17 +4,53 @@ import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import src.fr.api.Part;
|
||||
|
||||
|
||||
public class HtmlGenerator {
|
||||
|
||||
static final String HEADER = "<!DOCTYPE html><html><head><title>Cartailor</title></head>\n";
|
||||
static final String HEADER = "<!DOCTYPE html><html><head><title>Cartailor</title><style></style></head>\n";
|
||||
|
||||
static private String generateStringHTML(ConfigurationImpl config){
|
||||
String header ="<!DOCTYPE html>\n<html>\n<head>\n<title>Cartailor</title>\n";
|
||||
header += "<style>\n";
|
||||
header += "table{border-collapse: collapse;}\n";
|
||||
header +="th,td{border: 1px solid rgb(160 160 160);padding: 8px 10px;}";
|
||||
header += "</style>\n";
|
||||
header += "</head>\n";
|
||||
|
||||
String body = "<body>\n";
|
||||
body += "\t<table>\n";
|
||||
for(Part pt: config.getSelectedParts()){
|
||||
body += "\t\t<tr>\n";
|
||||
|
||||
body+= "\t\t\t<th>" + pt.getType().getCategory().getName() + "</th>\n";
|
||||
body+= "\t\t\t<th>" + pt.getType().getName() + "</th>\n";
|
||||
body+= "\t\t\t<th>" + ((PartImpl)pt).getPrice() + " €</th>\n";
|
||||
for(String pr: pt.getPropertyNames()){
|
||||
Optional<String> prOptional = pt.getProperty(pr);
|
||||
if(!prOptional.isEmpty()){
|
||||
body+= "\t\t\t<th>" + pr + " : " + prOptional.get() + "</th>\n";
|
||||
}
|
||||
}
|
||||
|
||||
body += "\t\t</tr>\n";
|
||||
|
||||
}
|
||||
body += "\t\t<tr>\n";
|
||||
body += "\t\t\t<th colspan=\"2\">Total Price : </th>\n";
|
||||
body += "\t\t\t<th>" + config.getTotalPrice() + " € </th>\n";
|
||||
body += "\t\t</tr>\n";
|
||||
|
||||
body += "\t</table>\n";
|
||||
|
||||
|
||||
|
||||
return HEADER + "";
|
||||
|
||||
body += "</body>\n";
|
||||
return header + body + "</html>";
|
||||
}
|
||||
|
||||
static public void generateHTML(ConfigurationImpl config) throws IOException{
|
||||
@@ -26,5 +62,6 @@ public class HtmlGenerator {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
|
||||
writer.write(content);
|
||||
}
|
||||
System.out.println(projectRoot+"\\cartailor.html");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,4 +94,8 @@ public class PartImpl implements Part {
|
||||
public int getPrice(){
|
||||
return this.price;
|
||||
}
|
||||
|
||||
public boolean isValidProperty(String propertyName){
|
||||
return this.properties.get(propertyName).possibleValues.contains(this.properties.get(propertyName).getter.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class Exterior extends PartImpl {
|
||||
|
||||
public Exterior(){
|
||||
this.addProperty("color", () -> getColor(), c -> setColor(c), colorSet);
|
||||
this.setProperty("color","white");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ package src.fr.test;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -110,6 +110,20 @@ public class test_V2 {
|
||||
assertTrue(config1.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_NotCompatibleProperty(){
|
||||
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
||||
config1.selectPart(EG210);
|
||||
config1.selectPart(TSF7);
|
||||
config1.selectPart(XS);
|
||||
config1.selectPart(IS);
|
||||
|
||||
config1.getPart(exterior).setProperty("color","gsqgsdf");
|
||||
|
||||
assertTrue(config1.getPart(exterior).getProperty("color").get()=="gsqgsdf");
|
||||
assertFalse(config1.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_NotProperty(){
|
||||
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
||||
@@ -118,7 +132,7 @@ public class test_V2 {
|
||||
config1.selectPart(XS);
|
||||
config1.selectPart(IS);
|
||||
|
||||
assertTrue(config1.getPart(exterior).getProperty("color").isEmpty());
|
||||
assertTrue(config1.getPart(exterior).getProperty("color").get()=="white");
|
||||
assertTrue(config1.isValid());
|
||||
}
|
||||
|
||||
@@ -158,4 +172,19 @@ public class test_V2 {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_html2(){
|
||||
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
||||
config1.selectPart(EG210);
|
||||
config1.selectPart(TSF7);
|
||||
config1.selectPart(XS);
|
||||
config1.selectPart(IS);
|
||||
config1.getPart(exterior).setProperty("color", "red");
|
||||
try {
|
||||
HtmlGenerator.generateHTML(config1);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user