();
+
+ when(userService.findAll()).thenReturn(usersExpected);
+
+ mockMvc.perform(get("/user"))
+ .andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.OK.value()))
+ .andExpect(jsonPath("$.length()", is(0)));
+ }
+
@Test
@DisplayName("Se busca un usuario a traves de un id")
void find_user_by_id() throws Exception {
@@ -50,20 +80,29 @@ void find_user_by_id() throws Exception {
when(userService.findById("4366fdc8-b32d-46bc-9df8-2e8ce68f0743")).thenReturn(userToReturn);
- mockMvc.perform(get("/user").param("id", "4366fdc8-b32d-46bc-9df8-2e8ce68f0743"))
+ mockMvc.perform(get("/user/userId").param("id", "4366fdc8-b32d-46bc-9df8-2e8ce68f0743"))
.andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.OK.value()))
.andExpect(jsonPath("$.id", is("4366fdc8-b32d-46bc-9df8-2e8ce68f0743")));
}
@Test
- @DisplayName("Se busca un usuarios a traves de un id que no existe")
+ @DisplayName("Se busca un usuario a traves de un id que no existe")
void find_user_by_not_exist_id() throws Exception {
when(userService.findById("5566fdc8-b32d-46bc-9df8-2e8ce68f0743")).thenThrow(NotFoundException.class);
- mockMvc.perform(get("/user").param("id", "5566fdc8-b32d-46bc-9df8-2e8ce68f0743"))
+ mockMvc.perform(get("/user/userId").param("id", "5566fdc8-b32d-46bc-9df8-2e8ce68f0743"))
.andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.NOT_FOUND.value()));
}
+ @Test
+ @DisplayName("Se busca un usuario a traves de un id y algo va mal")
+ void find_user_by_id_but_something_goes_wrong() throws Exception {
+ when(userService.findById("5566fdc8-b32d-46bc-9df8-2e8ce68f0743")).thenThrow(new RuntimeException("Service is unavailable"));
+
+ mockMvc.perform(get("/user/userId").param("id", "5566fdc8-b32d-46bc-9df8-2e8ce68f0743"))
+ .andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.SERVICE_UNAVAILABLE.value()));
+ }
+
@Test
@DisplayName("Se busca un usuario a traves de su nombre")
void find_user_by_name() throws Exception {
@@ -86,6 +125,15 @@ void find_user_by_not_exist_name() throws Exception {
.andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.NOT_FOUND.value()));
}
+ @Test
+ @DisplayName("Se busca un usuario a traves de un nombre y algo va mal")
+ void find_user_by_name_but_something_goes_wrong() throws Exception {
+ when(userService.findByName("ServiceUnavailablePlayer")).thenThrow(new RuntimeException("Service is unavailable"));
+
+ mockMvc.perform(get("/user/name").param("userName", "ServiceUnavailablePlayer"))
+ .andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.SERVICE_UNAVAILABLE.value()));
+ }
+
@Test
@DisplayName("Se crea un usuario")
void create_user() throws Exception {
@@ -124,6 +172,18 @@ void create_user_with_existent_name() throws Exception {
.andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.CONFLICT.value()));
}
+ @Test
+ @DisplayName("Se crea un usuario pero algo va mal")
+ void create_user_but_something_goes_wrong() throws Exception {
+ User userToCreate = new User(null, "Jugador 30", 1, 3, 1, 100, "Deportes");
+
+ when(userService.createUser(userToCreate)).thenThrow(new RuntimeException("Service is unavailable"));
+
+ mockMvc.perform(post("/user").contentType(MediaType.APPLICATION_JSON)
+ .content(asJsonString(userToCreate)))
+ .andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.SERVICE_UNAVAILABLE.value()));
+ }
+
@Test
@DisplayName("Se actualiza un usuario")
void update_user_() throws Exception {
@@ -162,7 +222,31 @@ void update_user_with_null_id() throws Exception {
.andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.NOT_FOUND.value()));
}
- public String asJsonString(Object obj) throws JsonProcessingException {
+ @Test
+ @DisplayName("Se actualiza un usuario con un nombre que ya existe")
+ void update_user_with_exist_name() throws Exception {
+ User userToUpdate = new User("1166fdc8-b32d-46bc-9df8-2e8ce68f0743", "Pablo", 1, 3, 1, 100, "Deportes");
+
+ when(userService.updateUser(userToUpdate)).thenThrow(ConflictException.class);
+
+ mockMvc.perform(put("/user").contentType(MediaType.APPLICATION_JSON)
+ .content(asJsonString(userToUpdate)))
+ .andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.CONFLICT.value()));
+ }
+
+ @Test
+ @DisplayName("Se actualiza un usuario pero algo va mal")
+ void update_user_but_something_goes_wrong() throws Exception {
+ User userToUpdate = new User("4366fdc8-b32d-46bc-9df8-2e8ce68f0743", "Jugador 3", 1, 3, 1, 100, "Deportes");
+
+ when(userService.updateUser(userToUpdate)).thenThrow(new RuntimeException("Service is unavailable"));
+
+ mockMvc.perform(put("/user").contentType(MediaType.APPLICATION_JSON)
+ .content(asJsonString(userToUpdate)))
+ .andDo(MockMvcResultHandlers.print()).andExpect(status().is(HttpStatus.SERVICE_UNAVAILABLE.value()));
+ }
+
+ private String asJsonString(Object obj) throws JsonProcessingException {
return new ObjectMapper().writeValueAsString(obj);
}
}
diff --git a/syg-backend/coverage/SYG-domain/index.html b/syg-backend/coverage/SYG-domain/index.html
new file mode 100644
index 0000000..e788ba4
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/index.html
@@ -0,0 +1 @@
+SYG-domainSYG-domain
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.exception/ConflictException.html b/syg-backend/coverage/SYG-domain/syg.domain.exception/ConflictException.html
new file mode 100644
index 0000000..4080f70
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.exception/ConflictException.html
@@ -0,0 +1 @@
+ConflictExceptionConflictException
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods |
Total | 0 of 4 | 100% | 0 of 0 | n/a | 0 | 1 | 0 | 2 | 0 | 1 |
ConflictException(String) | | 100% | | n/a | 0 | 1 | 0 | 2 | 0 | 1 |
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.exception/ConflictException.java.html b/syg-backend/coverage/SYG-domain/syg.domain.exception/ConflictException.java.html
new file mode 100644
index 0000000..e4a2195
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.exception/ConflictException.java.html
@@ -0,0 +1,19 @@
+ConflictException.javaConflictException.java
package syg.domain.exception;
+
+public class ConflictException extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8737231427849268021L;
+
+ /**
+ * Constructor con parámetros
+ *
+ * @param message
+ */
+ public ConflictException(String message) {
+ super(message);
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.exception/NotFoundException.html b/syg-backend/coverage/SYG-domain/syg.domain.exception/NotFoundException.html
new file mode 100644
index 0000000..47f51c1
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.exception/NotFoundException.html
@@ -0,0 +1 @@
+NotFoundExceptionNotFoundException
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods |
Total | 0 of 4 | 100% | 0 of 0 | n/a | 0 | 1 | 0 | 2 | 0 | 1 |
NotFoundException(String) | | 100% | | n/a | 0 | 1 | 0 | 2 | 0 | 1 |
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.exception/NotFoundException.java.html b/syg-backend/coverage/SYG-domain/syg.domain.exception/NotFoundException.java.html
new file mode 100644
index 0000000..3232238
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.exception/NotFoundException.java.html
@@ -0,0 +1,19 @@
+NotFoundException.javaNotFoundException.java
package syg.domain.exception;
+
+public class NotFoundException extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8737231427849268021L;
+
+ /**
+ * Constructor con parámetros
+ *
+ * @param message
+ */
+ public NotFoundException(String message) {
+ super(message);
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.exception/index.html b/syg-backend/coverage/SYG-domain/syg.domain.exception/index.html
new file mode 100644
index 0000000..e87ced5
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.exception/index.html
@@ -0,0 +1 @@
+syg.domain.exceptionsyg.domain.exception
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods | Missed | Classes |
Total | 0 of 8 | 100% | 0 of 0 | n/a | 0 | 2 | 0 | 4 | 0 | 2 | 0 | 2 |
NotFoundException | | 100% | | n/a | 0 | 1 | 0 | 2 | 0 | 1 | 0 | 1 |
ConflictException | | 100% | | n/a | 0 | 1 | 0 | 2 | 0 | 1 | 0 | 1 |
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.exception/index.source.html b/syg-backend/coverage/SYG-domain/syg.domain.exception/index.source.html
new file mode 100644
index 0000000..87db5f5
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.exception/index.source.html
@@ -0,0 +1 @@
+syg.domain.exceptionsyg.domain.exception
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model.enums/CategoryEnum.html b/syg-backend/coverage/SYG-domain/syg.domain.model.enums/CategoryEnum.html
new file mode 100644
index 0000000..4b53022
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model.enums/CategoryEnum.html
@@ -0,0 +1 @@
+CategoryEnumCategoryEnum
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model.enums/CategoryEnum.java.html b/syg-backend/coverage/SYG-domain/syg.domain.model.enums/CategoryEnum.java.html
new file mode 100644
index 0000000..5bd4b74
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model.enums/CategoryEnum.java.html
@@ -0,0 +1,27 @@
+CategoryEnum.javaCategoryEnum.java
package syg.domain.model.enums;
+
+public enum CategoryEnum {
+ Sport("Q349", "Deportes"),
+ Countries("Q6256", "Paises"),
+ Science("Q336", "Ciencia"),
+ Cine("Q11424", "Cine"),
+ Videogames("Q7889", "Videojuegos");
+
+ private final String value;
+ private final String label;
+
+ private CategoryEnum(String value, String label) {
+ this.value = value;
+ this.label = label;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model.enums/index.html b/syg-backend/coverage/SYG-domain/syg.domain.model.enums/index.html
new file mode 100644
index 0000000..6333387
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model.enums/index.html
@@ -0,0 +1 @@
+syg.domain.model.enumssyg.domain.model.enums
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods | Missed | Classes |
Total | 60 of 60 | 0% | 0 of 0 | n/a | 4 | 4 | 12 | 12 | 4 | 4 | 1 | 1 |
CategoryEnum | | 0% | | n/a | 4 | 4 | 12 | 12 | 4 | 4 | 1 | 1 |
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model.enums/index.source.html b/syg-backend/coverage/SYG-domain/syg.domain.model.enums/index.source.html
new file mode 100644
index 0000000..595dc16
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model.enums/index.source.html
@@ -0,0 +1 @@
+syg.domain.model.enumssyg.domain.model.enums
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods | Missed | Classes |
Total | 60 of 60 | 0% | 0 of 0 | n/a | 4 | 4 | 12 | 12 | 4 | 4 | 1 | 1 |
CategoryEnum.java | | 0% | | n/a | 4 | 4 | 12 | 12 | 4 | 4 | 1 | 1 |
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/Answer.html b/syg-backend/coverage/SYG-domain/syg.domain.model/Answer.html
new file mode 100644
index 0000000..20618c9
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/Answer.html
@@ -0,0 +1 @@
+AnswerAnswer
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/Answer.java.html b/syg-backend/coverage/SYG-domain/syg.domain.model/Answer.java.html
new file mode 100644
index 0000000..30d1ada
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/Answer.java.html
@@ -0,0 +1,22 @@
+Answer.javaAnswer.java
package syg.domain.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class Answer {
+
+ private Long id;
+
+ private String text;
+
+ private Boolean isCorrect;
+
+ public Answer(String text, Boolean isCorrect) {
+ this.text = text;
+ this.isCorrect = isCorrect;
+ }
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/Category.html b/syg-backend/coverage/SYG-domain/syg.domain.model/Category.html
new file mode 100644
index 0000000..b80c758
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/Category.html
@@ -0,0 +1 @@
+CategoryCategory
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/Category.java.html b/syg-backend/coverage/SYG-domain/syg.domain.model/Category.java.html
new file mode 100644
index 0000000..877de61
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/Category.java.html
@@ -0,0 +1,15 @@
+Category.javaCategory.java
package syg.domain.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class Category {
+
+ private Long id;
+
+ private String name;
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/Question.html b/syg-backend/coverage/SYG-domain/syg.domain.model/Question.html
new file mode 100644
index 0000000..d659b49
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/Question.html
@@ -0,0 +1 @@
+QuestionQuestion
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/Question.java.html b/syg-backend/coverage/SYG-domain/syg.domain.model/Question.java.html
new file mode 100644
index 0000000..bcc5a87
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/Question.java.html
@@ -0,0 +1,28 @@
+Question.javaQuestion.java
package syg.domain.model;
+
+import java.util.List;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class Question {
+
+ private Long id;
+
+ private String text;
+
+ private int timeLimit;
+
+ private Category category;
+
+ private List<Answer> answers;
+
+ public Question(String text) {
+ this.text = text;
+ this.timeLimit = 60;
+ }
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/User.html b/syg-backend/coverage/SYG-domain/syg.domain.model/User.html
new file mode 100644
index 0000000..34b5828
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/User.html
@@ -0,0 +1 @@
+UserUser
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/User.java.html b/syg-backend/coverage/SYG-domain/syg.domain.model/User.java.html
new file mode 100644
index 0000000..c8c71d2
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/User.java.html
@@ -0,0 +1,33 @@
+User.javaUser.java
package syg.domain.model;
+
+import jakarta.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class User {
+
+ private String id;
+
+ @NotNull
+ private String name;
+
+ @NotNull
+ private int totalGames;
+
+ @NotNull
+ private int correctAnswers;
+
+ @NotNull
+ private int inCorrectAnswers;
+
+ @NotNull
+ private int totalQuestionAnswered;
+
+ @NotNull
+ private String lastCategoryPlayed;
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/WikiData.html b/syg-backend/coverage/SYG-domain/syg.domain.model/WikiData.html
new file mode 100644
index 0000000..703cb91
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/WikiData.html
@@ -0,0 +1 @@
+WikiDataWikiData
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/WikiData.java.html b/syg-backend/coverage/SYG-domain/syg.domain.model/WikiData.java.html
new file mode 100644
index 0000000..411db5d
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/WikiData.java.html
@@ -0,0 +1,105 @@
+WikiData.javaWikiData.java
package syg.domain.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import org.eclipse.rdf4j.query.BindingSet;
+import org.eclipse.rdf4j.query.TupleQuery;
+import org.eclipse.rdf4j.query.TupleQueryResult;
+import org.eclipse.rdf4j.repository.Repository;
+import org.eclipse.rdf4j.repository.RepositoryConnection;
+import org.eclipse.rdf4j.repository.RepositoryException;
+import org.eclipse.rdf4j.repository.sparql.SPARQLRepository;
+import org.springframework.stereotype.Component;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Component
+public class WikiData {
+
+ public static final String WIKIDATA_URL = "https://query.wikidata.org/sparql";
+
+ public static final String WIKIDATA_QUERY = "SELECT DISTINCT (strafter(str(?item), \"http://www.wikidata.org/entity/\") AS ?entityId) ?label ?description WHERE {\n"
+ + " ?item wdt:P31 wd:%s .\n" + " ?item rdfs:label ?label .\n"
+ + " ?item schema:description ?description .\n"
+ + " FILTER(LANG(?label) = \"es\" && LANG(?description) = \"es\")\n" + " } LIMIT 50";
+
+ private String id;
+
+ private String description;
+
+ private String response;
+
+ /**
+ * Ejecuta la query de búsqueda de preguntas por categoria
+ *
+ * @param sparqlQuery
+ * @return
+ */
+ public List<WikiData> executeSparqlQuery(String sparqlQuery) {
+ List<WikiData> resultList = new ArrayList<>();
+
+ Repository repository = new SPARQLRepository(WIKIDATA_URL);
+ RepositoryConnection connection = null;
+
+ try {
+ repository.init();
+ connection = repository.getConnection();
+ TupleQuery query = connection.prepareTupleQuery(sparqlQuery);
+ try (TupleQueryResult result = query.evaluate()) {
+ while (result.hasNext()) {
+ BindingSet bindingSet = result.next();
+ String entityId = bindingSet.getValue("entityId").stringValue();
+ String description = bindingSet.getValue("description").stringValue();
+ String response = bindingSet.getValue("label").stringValue();
+ resultList.add(new WikiData(entityId, description, response));
+ }
+ }
+ } catch (RepositoryException e) {
+ throw new RepositoryException();
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ repository.shutDown();
+ }
+
+ return resultList;
+ }
+
+ /**
+ * Genéra números aleatorios para el índice de las preguntas incorrectas de wikidata.
+ * Nunca pueden coincidir con las correcta
+ *
+ * @param size El tamaño de la lista de preguntas
+ * @param excludedIndex El indice excluido para que no coincida con la respuesta correcta
+ * @param count El número de respuestas incorrectas
+ * @return
+ */
+ public List<Integer> generateUniqueRandomIndex(int size, int excludedIndex, int count) {
+ if (count > size - 1) {
+ throw new IllegalArgumentException("The number of numbers requested is greater than the available range.");
+ }
+
+ List<Integer> indices = new ArrayList<>();
+ Random random = new Random();
+
+ for (int i = 0; i < count; i++) {
+ int randomIndex;
+ do {
+ randomIndex = random.nextInt(size);
+ } while (randomIndex == excludedIndex || indices.contains(randomIndex));
+
+ indices.add(randomIndex);
+ }
+
+ return indices;
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/index.html b/syg-backend/coverage/SYG-domain/syg.domain.model/index.html
new file mode 100644
index 0000000..77db17c
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/index.html
@@ -0,0 +1 @@
+syg.domain.modelsyg.domain.model
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods | Missed | Classes |
Total | 811 of 1,086 | 25% | 154 of 172 | 10% | 120 | 157 | 41 | 69 | 35 | 71 | 0 | 5 |
WikiData | | 19% | | 7% | 30 | 35 | 30 | 35 | 9 | 14 | 0 | 1 |
Question | | 13% | | 0% | 30 | 36 | 5 | 11 | 10 | 16 | 0 | 1 |
Answer | | 12% | | 0% | 23 | 27 | 5 | 9 | 8 | 12 | 0 | 1 |
User | | 56% | | 39% | 20 | 39 | 0 | 10 | 2 | 20 | 0 | 1 |
Category | | 12% | | 0% | 17 | 20 | 1 | 4 | 6 | 9 | 0 | 1 |
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.model/index.source.html b/syg-backend/coverage/SYG-domain/syg.domain.model/index.source.html
new file mode 100644
index 0000000..d80c448
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.model/index.source.html
@@ -0,0 +1 @@
+syg.domain.modelsyg.domain.model
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.services/CategoryServiceImpl.html b/syg-backend/coverage/SYG-domain/syg.domain.services/CategoryServiceImpl.html
new file mode 100644
index 0000000..eaca8d7
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.services/CategoryServiceImpl.html
@@ -0,0 +1 @@
+CategoryServiceImplCategoryServiceImpl
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.services/CategoryServiceImpl.java.html b/syg-backend/coverage/SYG-domain/syg.domain.services/CategoryServiceImpl.java.html
new file mode 100644
index 0000000..19e419e
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.services/CategoryServiceImpl.java.html
@@ -0,0 +1,29 @@
+CategoryServiceImpl.javaCategoryServiceImpl.java
package syg.domain.services;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import syg.domain.model.Category;
+import syg.domain.ports.inbound.CategoryService;
+import syg.domain.ports.outbounds.CategoryPersistence;
+
+@Service
+public class CategoryServiceImpl implements CategoryService {
+
+ @Autowired
+ private CategoryPersistence categoryPersistence;
+
+ @Override
+ public List<Category> findAll() {
+ return categoryPersistence.findAll();
+ }
+
+ @Override
+ public Category findById(Long id) {
+ return categoryPersistence.findById(id);
+ }
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.services/QuestionsServiceImpl.html b/syg-backend/coverage/SYG-domain/syg.domain.services/QuestionsServiceImpl.html
new file mode 100644
index 0000000..f4bc38b
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.services/QuestionsServiceImpl.html
@@ -0,0 +1 @@
+QuestionsServiceImplQuestionsServiceImpl
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.services/QuestionsServiceImpl.java.html b/syg-backend/coverage/SYG-domain/syg.domain.services/QuestionsServiceImpl.java.html
new file mode 100644
index 0000000..cdb4ec5
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.services/QuestionsServiceImpl.java.html
@@ -0,0 +1,44 @@
+QuestionsServiceImpl.javaQuestionsServiceImpl.java
package syg.domain.services;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import syg.domain.model.Question;
+import syg.domain.ports.inbound.QuestionService;
+import syg.domain.ports.outbounds.QuestionPersistence;
+
+@Service
+public class QuestionsServiceImpl implements QuestionService {
+
+ @Autowired
+ private QuestionPersistence questionPersistence;
+
+ @Override
+ public void generateQuestions() {
+ questionPersistence.generatedQuestions();
+ }
+
+ @Override
+ public List<Question> findAll() {
+ return questionPersistence.findAll();
+ }
+
+ @Override
+ public Question findById(Long id) {
+ return questionPersistence.findById(id);
+ }
+
+ @Override
+ public List<Question> findByCategory(Long categoryId) {
+ return questionPersistence.findByCategory(categoryId);
+ }
+
+ @Override
+ public void deleteQuestions() {
+ questionPersistence.deleteQuestions();
+ }
+}
+
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.services/UserServiceImpl.html b/syg-backend/coverage/SYG-domain/syg.domain.services/UserServiceImpl.html
new file mode 100644
index 0000000..b76029e
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.services/UserServiceImpl.html
@@ -0,0 +1 @@
+UserServiceImplUserServiceImpl
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.services/UserServiceImpl.java.html b/syg-backend/coverage/SYG-domain/syg.domain.services/UserServiceImpl.java.html
new file mode 100644
index 0000000..7fbf1a1
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.services/UserServiceImpl.java.html
@@ -0,0 +1,44 @@
+UserServiceImpl.javaUserServiceImpl.java
package syg.domain.services;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import syg.domain.model.User;
+import syg.domain.ports.inbound.UserService;
+import syg.domain.ports.outbounds.UserPersistence;
+
+@Service
+public class UserServiceImpl implements UserService{
+
+ @Autowired
+ private UserPersistence userPersistence;
+
+ @Override
+ public List<User> findAll() {
+ return userPersistence.findAll();
+ }
+
+ @Override
+ public User findById(String id) {
+ return userPersistence.findById(id);
+ }
+
+ @Override
+ public User findByName(String name) {
+ return userPersistence.findByName(name);
+ }
+
+ @Override
+ public User createUser(User user) {
+ return userPersistence.createUser(user);
+ }
+
+ @Override
+ public User updateUser(User user) {
+ return userPersistence.updateUser(user);
+ }
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.services/index.html b/syg-backend/coverage/SYG-domain/syg.domain.services/index.html
new file mode 100644
index 0000000..fb227e3
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.services/index.html
@@ -0,0 +1 @@
+syg.domain.servicessyg.domain.services
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-domain/syg.domain.services/index.source.html b/syg-backend/coverage/SYG-domain/syg.domain.services/index.source.html
new file mode 100644
index 0000000..15525ec
--- /dev/null
+++ b/syg-backend/coverage/SYG-domain/syg.domain.services/index.source.html
@@ -0,0 +1 @@
+syg.domain.servicessyg.domain.services
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/index.html b/syg-backend/coverage/SYG-mysql-adapter/index.html
new file mode 100644
index 0000000..e46ee17
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/index.html
@@ -0,0 +1 @@
+SYG-mysql-adapterSYG-mysql-adapter
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/CategoryAdapter.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/CategoryAdapter.html
new file mode 100644
index 0000000..9794d53
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/CategoryAdapter.html
@@ -0,0 +1 @@
+CategoryAdapterCategoryAdapter
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/CategoryAdapter.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/CategoryAdapter.java.html
new file mode 100644
index 0000000..6d83dd9
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/CategoryAdapter.java.html
@@ -0,0 +1,40 @@
+CategoryAdapter.javaCategoryAdapter.java
package syg.mysql.adapter;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import syg.domain.exception.NotFoundException;
+import syg.domain.model.Category;
+import syg.domain.ports.outbounds.CategoryPersistence;
+import syg.mysql.entities.CategoryEntity;
+import syg.mysql.mapper.CategoryMapper;
+import syg.mysql.repositories.CategoryRepository;
+
+@Component
+public class CategoryAdapter implements CategoryPersistence {
+
+ @Autowired
+ private CategoryRepository categoryRepository;
+
+ @Autowired
+ private CategoryMapper categoryMapper;
+
+ @Override
+ public List<Category> findAll() {
+ return categoryMapper.toDomain(categoryRepository.findAll());
+ }
+
+ @Override
+ public Category findById(Long id) {
+ Optional<CategoryEntity> optionalCategory = categoryRepository.findById(id);
+ if(!optionalCategory.isPresent()) {
+ throw new NotFoundException("The category with id " + id + " does not exist");
+ }
+ return categoryMapper.toDomain(categoryRepository.findById(id).get());
+ }
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/QuestionAdapter.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/QuestionAdapter.html
new file mode 100644
index 0000000..0ffaae4
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/QuestionAdapter.html
@@ -0,0 +1 @@
+QuestionAdapterQuestionAdapter
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/QuestionAdapter.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/QuestionAdapter.java.html
new file mode 100644
index 0000000..e87ab43
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/QuestionAdapter.java.html
@@ -0,0 +1,119 @@
+QuestionAdapter.javaQuestionAdapter.java
package syg.mysql.adapter;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import syg.domain.exception.NotFoundException;
+import syg.domain.model.Answer;
+import syg.domain.model.Question;
+import syg.domain.model.WikiData;
+import syg.domain.model.enums.CategoryEnum;
+import syg.domain.ports.outbounds.QuestionPersistence;
+import syg.mysql.entities.AnswerEntity;
+import syg.mysql.entities.CategoryEntity;
+import syg.mysql.entities.QuestionEntity;
+import syg.mysql.mapper.AnswerMapper;
+import syg.mysql.mapper.QuestionMapper;
+import syg.mysql.repositories.CategoryRepository;
+import syg.mysql.repositories.QuestionRepository;
+
+@Component
+public class QuestionAdapter implements QuestionPersistence {
+
+ @Autowired
+ private QuestionRepository questionRepository;
+
+ @Autowired
+ private CategoryRepository categoryRepository;
+
+ @Autowired
+ private QuestionMapper questionMapper;
+
+ @Autowired
+ private AnswerMapper answerMapper;
+
+ @Autowired
+ private WikiData wikiData;
+
+ @Override
+ public List<Question> findAll() {
+ return questionMapper.toDomain(questionRepository.findAll());
+ }
+
+ @Override
+ public Question findById(Long id) {
+ Optional<QuestionEntity> optionalQuestion = questionRepository.findById(id);
+ if (!optionalQuestion.isPresent()) {
+ throw new NotFoundException("The question with id " + id + " does not exist");
+ }
+ return questionMapper.toDomain(questionRepository.findById(id).get());
+ }
+
+ @Override
+ public List<Question> findByCategory(Long categoryId) {
+ return questionMapper.toDomain(questionRepository.findByCategory_Id(categoryId));
+ }
+
+ @Override
+ public void deleteQuestions() {
+ questionRepository.deleteAll();
+ }
+
+ @Override
+ public void generatedQuestions() {
+ List<CategoryEntity> categoriesEntities = categoryRepository.findAll();
+ for (CategoryEnum categoryEnum : CategoryEnum.values()) {
+ CategoryEntity category = null;
+ for (CategoryEntity categoryEntity : categoriesEntities) {
+ if (categoryEntity.getName().equals(categoryEnum.getLabel())) {
+ category = categoryEntity;
+ break;
+ }
+ }
+
+ String sparqlQuery = String.format(WikiData.WIKIDATA_QUERY, categoryEnum.getValue());
+ List<WikiData> responses = wikiData.executeSparqlQuery(sparqlQuery);
+
+ List<QuestionEntity> questions = generatedQuestionsLogic(responses, category);
+ questionRepository.saveAll(questions);
+ }
+ }
+
+ /**
+ * Genera las preguntas, con sus respuestas incorrecta.
+ * Las forma de manera totalmente al azar, para que no se repitan nunca.
+ *
+ * @param wikisQuestions Las preguntas generadas
+ * @param categoryEntity La categoria a la que pertencen
+ * @return
+ */
+ private List<QuestionEntity> generatedQuestionsLogic(List<WikiData> wikisQuestions, CategoryEntity categoryEntity) {
+ List<QuestionEntity> questionsGenerated = new ArrayList<QuestionEntity>();
+ for (int i = 0; i < wikisQuestions.size(); i++) {
+ Question question = new Question(wikisQuestions.get(i).getDescription().substring(0, 1).toUpperCase()
+ + wikisQuestions.get(i).getDescription().substring(1));
+ List<Answer> answers = new ArrayList<Answer>();
+ Answer correctAnswer = new Answer(wikisQuestions.get(i).getResponse().substring(0, 1).toUpperCase()
+ + wikisQuestions.get(i).getResponse().substring(1), true);
+
+ List<Integer> incorrectResponses = wikiData.generateUniqueRandomIndex(wikisQuestions.size(), i, 3);
+ for (Integer incorrectResponseIndex : incorrectResponses) {
+ answers.add(new Answer(wikisQuestions.get(incorrectResponseIndex).getResponse(), false));
+ }
+ answers.add(correctAnswer);
+
+ QuestionEntity questionEntity = questionMapper.toEntity(question);
+ questionEntity.setCategory(categoryEntity);
+ List<AnswerEntity> answersEntities = answerMapper.toEntity(answers);
+ answersEntities.stream().forEach(answer -> answer.setQuestion(questionEntity));
+ questionEntity.setAnswers(answersEntities);
+ questionsGenerated.add(questionEntity);
+ }
+ return questionsGenerated;
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/UserAdapter.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/UserAdapter.html
new file mode 100644
index 0000000..dfbb13a
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/UserAdapter.html
@@ -0,0 +1 @@
+UserAdapterUserAdapter
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/UserAdapter.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/UserAdapter.java.html
new file mode 100644
index 0000000..12b888b
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/UserAdapter.java.html
@@ -0,0 +1,74 @@
+UserAdapter.javaUserAdapter.java
package syg.mysql.adapter;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.stereotype.Component;
+
+import syg.domain.exception.ConflictException;
+import syg.domain.exception.NotFoundException;
+import syg.domain.model.User;
+import syg.domain.ports.outbounds.UserPersistence;
+import syg.mysql.entities.UserEntity;
+import syg.mysql.mapper.UserMapper;
+import syg.mysql.repositories.UserRepository;
+
+@Component
+public class UserAdapter implements UserPersistence {
+
+ @Autowired
+ private UserRepository userRepository;
+
+ @Autowired
+ private UserMapper userMapper;
+
+ @Override
+ public List<User> findAll() {
+ List<UserEntity> usersEntity = userRepository.findAll();
+ return userMapper.toDomain(usersEntity);
+ }
+
+ @Override
+ public User findById(String id) {
+ Optional<UserEntity> optionalUserEntity = userRepository.findById(id);
+ if(optionalUserEntity.isEmpty()) {
+ throw new NotFoundException("The user with id " + id + " does not exist");
+ }
+ return userMapper.toDomain(optionalUserEntity.get());
+ }
+
+ @Override
+ public User findByName(String name) {
+ Optional<UserEntity> optionalUserEntity = userRepository.findByName(name);
+ if(optionalUserEntity.isEmpty()) {
+ throw new NotFoundException("The user with name " + name + " does not exist");
+ }
+ return userMapper.toDomain(optionalUserEntity.get());
+ }
+
+ @Override
+ public User createUser(User user) {
+ if(user.getId() != null && (userRepository.findById(user.getId()).isPresent() || userRepository.findByName(user.getName()).isPresent())) {
+ throw new ConflictException("The user with id " + user.getId() + " alredy exist");
+ }
+ try {
+ UserEntity userEntity = userRepository.save(userMapper.toEntity(user));
+ return userMapper.toDomain(userEntity);
+ } catch (DataIntegrityViolationException e) {
+ throw new ConflictException("The user with name " + user.getName() + " alredy exist");
+ }
+ }
+
+ @Override
+ public User updateUser(User user) {
+ if(user.getId() == null || userRepository.findById(user.getId()).isEmpty()) {
+ throw new NotFoundException("The user with id " + user.getId() + " not exist");
+ }
+ UserEntity userEntity = userRepository.save(userMapper.toEntity(user));
+ return userMapper.toDomain(userEntity);
+ }
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/index.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/index.html
new file mode 100644
index 0000000..443e6f6
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/index.html
@@ -0,0 +1 @@
+syg.mysql.adaptersyg.mysql.adapter
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods | Missed | Classes |
Total | 208 of 407 | 48% | 10 of 28 | 64% | 9 | 31 | 36 | 68 | 4 | 17 | 0 | 3 |
QuestionAdapter | | 17% | | 16% | 9 | 14 | 34 | 41 | 4 | 8 | 0 | 1 |
UserAdapter | | 93% | | 100% | 0 | 13 | 2 | 21 | 0 | 6 | 0 | 1 |
CategoryAdapter | | 100% | | 100% | 0 | 4 | 0 | 6 | 0 | 3 | 0 | 1 |
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/index.source.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/index.source.html
new file mode 100644
index 0000000..8fc73b0
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.adapter/index.source.html
@@ -0,0 +1 @@
+syg.mysql.adaptersyg.mysql.adapter
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/AnswerEntity.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/AnswerEntity.html
new file mode 100644
index 0000000..bef62cc
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/AnswerEntity.html
@@ -0,0 +1 @@
+AnswerEntityAnswerEntity
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/AnswerEntity.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/AnswerEntity.java.html
new file mode 100644
index 0000000..292e3e0
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/AnswerEntity.java.html
@@ -0,0 +1,43 @@
+AnswerEntity.javaAnswerEntity.java
package syg.mysql.entities;
+
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.JoinColumn;
+import jakarta.persistence.ManyToOne;
+import jakarta.persistence.Table;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Entity
+@Table(name = "ANSWERS")
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class AnswerEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "ID")
+ private Long id;
+
+ @Column(name = "TEXT")
+ private String text;
+
+ @Column(name = "IS_CORRECT")
+ private Boolean isCorrect;
+
+ @ManyToOne
+ @JoinColumn(name = "question", referencedColumnName = "ID")
+ private QuestionEntity question;
+
+ public AnswerEntity(Long id, String text, Boolean isCorrect) {
+ this.id = id;
+ this.text = text;
+ this.isCorrect = isCorrect;
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/CategoryEntity.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/CategoryEntity.html
new file mode 100644
index 0000000..82ba731
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/CategoryEntity.html
@@ -0,0 +1 @@
+CategoryEntityCategoryEntity
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/CategoryEntity.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/CategoryEntity.java.html
new file mode 100644
index 0000000..dab021f
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/CategoryEntity.java.html
@@ -0,0 +1,41 @@
+CategoryEntity.javaCategoryEntity.java
package syg.mysql.entities;
+
+import java.util.List;
+
+import jakarta.persistence.CascadeType;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.OneToMany;
+import jakarta.persistence.Table;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Entity
+@Table(name = "CATEGORIES")
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class CategoryEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "ID")
+ private Long id;
+
+ @Column(name = "NAME")
+ private String name;
+
+ @OneToMany(mappedBy = "category", cascade = CascadeType.ALL)
+ private List<QuestionEntity> questions;
+
+ public CategoryEntity(Long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/QuestionEntity.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/QuestionEntity.html
new file mode 100644
index 0000000..30df242
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/QuestionEntity.html
@@ -0,0 +1 @@
+QuestionEntityQuestionEntity
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/QuestionEntity.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/QuestionEntity.java.html
new file mode 100644
index 0000000..7484db6
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/QuestionEntity.java.html
@@ -0,0 +1,52 @@
+QuestionEntity.javaQuestionEntity.java
package syg.mysql.entities;
+
+import java.util.List;
+
+import jakarta.persistence.CascadeType;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.JoinColumn;
+import jakarta.persistence.ManyToOne;
+import jakarta.persistence.OneToMany;
+import jakarta.persistence.Table;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Entity
+@Table(name = "QUESTIONS")
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class QuestionEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "ID")
+ private Long id;
+
+ @Column(name = "TEXT")
+ private String text;
+
+ @Column(name = "TIME_LIMIT")
+ private Integer timeLimit;
+
+ @ManyToOne
+ @JoinColumn(name = "category", referencedColumnName = "ID")
+ private CategoryEntity category;
+
+ @OneToMany(mappedBy = "question", cascade = CascadeType.ALL)
+ private List<AnswerEntity> answers;
+
+ public QuestionEntity(Long id, String text, int timeLimit, CategoryEntity category) {
+ this.id = id;
+ this.text = text;
+ this.timeLimit = timeLimit;
+ this.category = category;
+ }
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/UserEntity.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/UserEntity.html
new file mode 100644
index 0000000..4be4a90
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/UserEntity.html
@@ -0,0 +1 @@
+UserEntityUserEntity
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/UserEntity.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/UserEntity.java.html
new file mode 100644
index 0000000..8da16ab
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/UserEntity.java.html
@@ -0,0 +1,40 @@
+UserEntity.javaUserEntity.java
package syg.mysql.entities;
+
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import jakarta.persistence.Table;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Entity
+@Table(name = "USERS")
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class UserEntity {
+
+ @Id
+ @Column(name = "ID")
+ private String id;
+
+ @Column(name = "NAME")
+ private String name;
+
+ @Column(name = "TOTAL_GAMES")
+ private int totalGames;
+
+ @Column(name = "CORRECT_ANSWERS")
+ private int correctAnswers;
+
+ @Column(name = "INCORRECT_ANSWERS")
+ private int inCorrectAnswers;
+
+ @Column(name = "TOTAL_QUESTIONS_ANSWERED")
+ private int totalQuestionAnswered;
+
+ @Column(name = "LAST_CATEGORY_PLAYED")
+ private String lastCategoryPlayed;
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/index.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/index.html
new file mode 100644
index 0000000..188a585
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/index.html
@@ -0,0 +1 @@
+syg.mysql.entitiessyg.mysql.entities
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods | Missed | Classes |
Total | 720 of 938 | 23% | 137 of 152 | 9% | 112 | 141 | 7 | 46 | 37 | 65 | 0 | 4 |
QuestionEntity | | 19% | | 0% | 32 | 40 | 1 | 14 | 9 | 17 | 0 | 1 |
AnswerEntity | | 10% | | 0% | 29 | 34 | 3 | 12 | 10 | 15 | 0 | 1 |
CategoryEntity | | 10% | | 0% | 24 | 28 | 3 | 10 | 9 | 13 | 0 | 1 |
UserEntity | | 45% | | 39% | 27 | 39 | 0 | 10 | 9 | 20 | 0 | 1 |
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/index.source.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/index.source.html
new file mode 100644
index 0000000..08080c9
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.entities/index.source.html
@@ -0,0 +1 @@
+syg.mysql.entitiessyg.mysql.entities
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/AnswerMapper.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/AnswerMapper.html
new file mode 100644
index 0000000..3d533aa
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/AnswerMapper.html
@@ -0,0 +1 @@
+AnswerMapperAnswerMapper
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/AnswerMapper.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/AnswerMapper.java.html
new file mode 100644
index 0000000..ab16fd5
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/AnswerMapper.java.html
@@ -0,0 +1,38 @@
+AnswerMapper.javaAnswerMapper.java
package syg.mysql.mapper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.stereotype.Component;
+
+import syg.domain.model.Answer;
+import syg.mysql.entities.AnswerEntity;
+
+@Component
+public class AnswerMapper {
+
+ public AnswerEntity toEntity(Answer answer) {
+ return new AnswerEntity(answer.getId(), answer.getText(), answer.getIsCorrect());
+ }
+
+ public List<AnswerEntity> toEntity(List<Answer> answers) {
+ List<AnswerEntity> answersEntity = new ArrayList<AnswerEntity>();
+ for (Answer answer : answers) {
+ answersEntity.add(toEntity(answer));
+ }
+ return answersEntity;
+ }
+
+ public Answer toDomain(AnswerEntity answerEntity) {
+ return new Answer(answerEntity.getId(), answerEntity.getText(), answerEntity.getIsCorrect());
+ }
+
+ public List<Answer> toDomain(List<AnswerEntity> answersEntity) {
+ List<Answer> answers = new ArrayList<Answer>();
+ for (AnswerEntity answerEntity : answersEntity) {
+ answers.add(toDomain(answerEntity));
+ }
+ return answers;
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/CategoryMapper.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/CategoryMapper.html
new file mode 100644
index 0000000..76f6a3a
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/CategoryMapper.html
@@ -0,0 +1 @@
+CategoryMapperCategoryMapper
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/CategoryMapper.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/CategoryMapper.java.html
new file mode 100644
index 0000000..2892c85
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/CategoryMapper.java.html
@@ -0,0 +1,38 @@
+CategoryMapper.javaCategoryMapper.java
package syg.mysql.mapper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.stereotype.Component;
+
+import syg.domain.model.Category;
+import syg.mysql.entities.CategoryEntity;
+
+@Component
+public class CategoryMapper {
+
+ public CategoryEntity toEntity(Category category) {
+ return new CategoryEntity(category.getId(), category.getName());
+ }
+
+ public List<CategoryEntity> toEntity(List<Category> categories) {
+ List<CategoryEntity> categoriesEntity = new ArrayList<CategoryEntity>();
+ for (Category category : categories) {
+ categoriesEntity.add(toEntity(category));
+ }
+ return categoriesEntity;
+ }
+
+ public Category toDomain(CategoryEntity categoryEntity) {
+ return new Category(categoryEntity.getId(), categoryEntity.getName());
+ }
+
+ public List<Category> toDomain(List<CategoryEntity> categoriesEntity) {
+ List<Category> categories = new ArrayList<Category>();
+ for (CategoryEntity categoryEntity : categoriesEntity) {
+ categories.add(toDomain(categoryEntity));
+ }
+ return categories;
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/QuestionMapper.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/QuestionMapper.html
new file mode 100644
index 0000000..9c1dc2c
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/QuestionMapper.html
@@ -0,0 +1 @@
+QuestionMapperQuestionMapper
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/QuestionMapper.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/QuestionMapper.java.html
new file mode 100644
index 0000000..cdfc103
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/QuestionMapper.java.html
@@ -0,0 +1,49 @@
+QuestionMapper.javaQuestionMapper.java
package syg.mysql.mapper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import syg.domain.model.Question;
+import syg.mysql.entities.AnswerEntity;
+import syg.mysql.entities.QuestionEntity;
+
+@Component
+public class QuestionMapper {
+
+ @Autowired
+ private AnswerMapper answerMapper;
+
+ @Autowired
+ private CategoryMapper categoryMapper;
+
+ public QuestionEntity toEntity(Question question) {
+ return new QuestionEntity(question.getId(), question.getText(), 60,
+ question.getCategory() != null ? categoryMapper.toEntity(question.getCategory()) : null);
+ }
+
+ public List<QuestionEntity> toEntity(List<Question> questions) {
+ List<QuestionEntity> questionsEntity = new ArrayList<QuestionEntity>();
+ for (Question question : questions) {
+ questionsEntity.add(toEntity(question));
+ }
+ return questionsEntity;
+ }
+
+ public Question toDomain(QuestionEntity questionEntity) {
+ return new Question(questionEntity.getId(), questionEntity.getText(), questionEntity.getTimeLimit(),
+ questionEntity.getCategory() != null ? categoryMapper.toDomain(questionEntity.getCategory()) : null,
+ answerMapper.toDomain(questionEntity.getAnswers() != null ? questionEntity.getAnswers() : new ArrayList<AnswerEntity>()));
+ }
+
+ public List<Question> toDomain(List<QuestionEntity> questionsEntity) {
+ List<Question> questions = new ArrayList<Question>();
+ for (QuestionEntity questionEntity : questionsEntity) {
+ questions.add(toDomain(questionEntity));
+ }
+ return questions;
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/UserMapper.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/UserMapper.html
new file mode 100644
index 0000000..604db24
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/UserMapper.html
@@ -0,0 +1 @@
+UserMapperUserMapper
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/UserMapper.java.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/UserMapper.java.html
new file mode 100644
index 0000000..9b43305
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/UserMapper.java.html
@@ -0,0 +1,41 @@
+UserMapper.javaUserMapper.java
package syg.mysql.mapper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.stereotype.Component;
+
+import syg.domain.model.User;
+import syg.mysql.entities.UserEntity;
+
+@Component
+public class UserMapper {
+
+ public UserEntity toEntity(User user) {
+ return new UserEntity(user.getId(),user.getName(), user.getTotalGames(),
+ user.getCorrectAnswers(), user.getInCorrectAnswers(), user.getTotalQuestionAnswered(), user.getLastCategoryPlayed());
+ }
+
+ public List<UserEntity> toEntity(List<User> users) {
+ List<UserEntity> usersEntity = new ArrayList<UserEntity>();
+ for (User user : users) {
+ usersEntity.add(toEntity(user));
+ }
+ return usersEntity;
+ }
+
+ public User toDomain(UserEntity userEntity) {
+ return new User(userEntity.getId(),userEntity.getName(), userEntity.getTotalGames(),
+ userEntity.getCorrectAnswers(), userEntity.getInCorrectAnswers(), userEntity.getTotalQuestionAnswered(), userEntity.getLastCategoryPlayed());
+ }
+
+ public List<User> toDomain(List<UserEntity> usersEntity) {
+ List<User> users = new ArrayList<User>();
+ for (UserEntity userEntity : usersEntity) {
+ users.add(toDomain(userEntity));
+ }
+ return users;
+ }
+
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/index.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/index.html
new file mode 100644
index 0000000..ab849e1
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/index.html
@@ -0,0 +1 @@
+syg.mysql.mappersyg.mysql.mapper
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods | Missed | Classes |
Total | 6 of 320 | 98% | 1 of 22 | 95% | 1 | 31 | 0 | 57 | 0 | 20 | 0 | 4 |
QuestionMapper | | 94% | | 90% | 1 | 10 | 0 | 16 | 0 | 5 | 0 | 1 |
UserMapper | | 100% | | 100% | 0 | 7 | 0 | 15 | 0 | 5 | 0 | 1 |
AnswerMapper | | 100% | | 100% | 0 | 7 | 0 | 13 | 0 | 5 | 0 | 1 |
CategoryMapper | | 100% | | 100% | 0 | 7 | 0 | 13 | 0 | 5 | 0 | 1 |
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/index.source.html b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/index.source.html
new file mode 100644
index 0000000..7a1d722
--- /dev/null
+++ b/syg-backend/coverage/SYG-mysql-adapter/syg.mysql.mapper/index.source.html
@@ -0,0 +1 @@
+syg.mysql.mappersyg.mysql.mapper
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-rest-controller/index.html b/syg-backend/coverage/SYG-rest-controller/index.html
new file mode 100644
index 0000000..d3dd05e
--- /dev/null
+++ b/syg-backend/coverage/SYG-rest-controller/index.html
@@ -0,0 +1 @@
+SYG-rest-controllerSYG-rest-controller
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods | Missed | Classes |
Total | 84 of 250 | 66% | 1 of 4 | 75% | 2 | 15 | 23 | 61 | 1 | 13 | 0 | 3 |
syg.controller | | 66% | | 75% | 2 | 15 | 23 | 61 | 1 | 13 | 0 | 3 |
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-rest-controller/syg.controller/CategoryController.html b/syg-backend/coverage/SYG-rest-controller/syg.controller/CategoryController.html
new file mode 100644
index 0000000..821baf4
--- /dev/null
+++ b/syg-backend/coverage/SYG-rest-controller/syg.controller/CategoryController.html
@@ -0,0 +1 @@
+CategoryControllerCategoryController
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-rest-controller/syg.controller/CategoryController.java.html b/syg-backend/coverage/SYG-rest-controller/syg.controller/CategoryController.java.html
new file mode 100644
index 0000000..55934c8
--- /dev/null
+++ b/syg-backend/coverage/SYG-rest-controller/syg.controller/CategoryController.java.html
@@ -0,0 +1,43 @@
+CategoryController.javaCategoryController.java
package syg.controller;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import syg.domain.exception.NotFoundException;
+import syg.domain.model.Category;
+import syg.domain.ports.inbound.CategoryService;
+
+@RestController
+@RequestMapping("/category")
+public class CategoryController {
+
+ @Autowired
+ private CategoryService categoryService;
+
+ @GetMapping
+ public ResponseEntity<Object> findAll() {
+ List<Category> categories = categoryService.findAll();
+ return ResponseEntity.status(HttpStatus.OK).body(categories);
+ }
+
+ @GetMapping("/id")
+ public ResponseEntity<Object> findById(@RequestParam(name = "id") Long id) {
+ try {
+ Category category = categoryService.findById(id);
+ return ResponseEntity.status(HttpStatus.OK).body(category);
+ }catch (NotFoundException e) {
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
+ }
+ catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
+ }
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-rest-controller/syg.controller/QuestionsController.html b/syg-backend/coverage/SYG-rest-controller/syg.controller/QuestionsController.html
new file mode 100644
index 0000000..1ebf758
--- /dev/null
+++ b/syg-backend/coverage/SYG-rest-controller/syg.controller/QuestionsController.html
@@ -0,0 +1 @@
+QuestionsControllerQuestionsController
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-rest-controller/syg.controller/QuestionsController.java.html b/syg-backend/coverage/SYG-rest-controller/syg.controller/QuestionsController.java.html
new file mode 100644
index 0000000..d77f408
--- /dev/null
+++ b/syg-backend/coverage/SYG-rest-controller/syg.controller/QuestionsController.java.html
@@ -0,0 +1,56 @@
+QuestionsController.javaQuestionsController.java
package syg.controller;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import syg.domain.exception.NotFoundException;
+import syg.domain.model.Question;
+import syg.domain.ports.inbound.QuestionService;
+
+@RestController
+@RequestMapping("/question")
+public class QuestionsController {
+
+ @Autowired
+ private QuestionService questionService;
+
+ @GetMapping
+ public ResponseEntity<Object> findAll() {
+ List<Question> questions = questionService.findAll();
+ if(questions.size() <= 0) {
+ return ResponseEntity.status(HttpStatus.OK).body(questions);
+ }
+ Collections.shuffle(questions);
+ return ResponseEntity.status(HttpStatus.OK).body(questions.subList(0, Math.min(questions.size(), 15)));
+ }
+
+ @GetMapping("/id")
+ public ResponseEntity<Object> findById(@RequestParam(name = "id") Long id) {
+ try {
+ Question question = questionService.findById(id);
+ return ResponseEntity.status(HttpStatus.OK).body(question);
+ } catch (NotFoundException e) {
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
+ } catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
+ }
+ }
+ @GetMapping("/category")
+ public ResponseEntity<Object> findByCategory(@RequestParam(name = "categoryId") Long categoryId) {
+ List<Question> questions = questionService.findByCategory(categoryId);
+ if(questions.size() <= 0) {
+ return ResponseEntity.status(HttpStatus.OK).body(questions);
+ }
+ Collections.shuffle(questions);
+ return ResponseEntity.status(HttpStatus.OK).body(questions.subList(0, Math.min(questions.size(), 15)));
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-rest-controller/syg.controller/UserController.html b/syg-backend/coverage/SYG-rest-controller/syg.controller/UserController.html
new file mode 100644
index 0000000..487b962
--- /dev/null
+++ b/syg-backend/coverage/SYG-rest-controller/syg.controller/UserController.html
@@ -0,0 +1 @@
+UserControllerUserController
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-rest-controller/syg.controller/UserController.java.html b/syg-backend/coverage/SYG-rest-controller/syg.controller/UserController.java.html
new file mode 100644
index 0000000..345a46c
--- /dev/null
+++ b/syg-backend/coverage/SYG-rest-controller/syg.controller/UserController.java.html
@@ -0,0 +1,95 @@
+UserController.javaUserController.java
package syg.controller;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import syg.domain.exception.ConflictException;
+import syg.domain.exception.NotFoundException;
+import syg.domain.model.User;
+import syg.domain.ports.inbound.UserService;
+
+@RestController
+@RequestMapping("/user")
+public class UserController {
+
+ @Autowired
+ private UserService userService;
+
+ @GetMapping
+ public ResponseEntity<Object> findUsers() {
+ try {
+ List<User> users = userService.findAll();
+ return ResponseEntity.status(HttpStatus.OK).body(users);
+ }catch (NotFoundException e) {
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
+ }
+ catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
+ }
+ }
+
+ @GetMapping("/userId")
+ public ResponseEntity<Object> findUser(@RequestParam(name = "id") String id) {
+ try {
+ User user = userService.findById(id);
+ return ResponseEntity.status(HttpStatus.OK).body(user);
+ }catch (NotFoundException e) {
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
+ }
+ catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
+ }
+ }
+
+ @GetMapping("/name")
+ public ResponseEntity<Object> findName(@RequestParam(name = "userName") String userName) {
+ try {
+ User user = userService.findByName(userName);
+ return ResponseEntity.status(HttpStatus.OK).body(user);
+ }catch (NotFoundException e) {
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
+ }
+ catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
+ }
+ }
+
+ @PostMapping
+ public ResponseEntity<Object> createUser(@RequestBody User user) {
+ try {
+ User userCreated = userService.createUser(user);
+ return ResponseEntity.status(HttpStatus.OK).body(userCreated);
+ } catch (NotFoundException e) {
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
+ } catch (ConflictException e) {
+ return ResponseEntity.status(HttpStatus.CONFLICT).body(e.getMessage());
+ } catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
+ }
+ }
+
+ @PutMapping
+ public ResponseEntity<Object> updateUser(@RequestBody User user) {
+ try {
+ User userUpdated = userService.updateUser(user);
+ return ResponseEntity.status(HttpStatus.OK).body(userUpdated);
+ } catch (NotFoundException e) {
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
+ } catch (ConflictException e) {
+ return ResponseEntity.status(HttpStatus.CONFLICT).body(e.getMessage());
+ } catch (Exception e) {
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
+ }
+ }
+}
+
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-rest-controller/syg.controller/index.html b/syg-backend/coverage/SYG-rest-controller/syg.controller/index.html
new file mode 100644
index 0000000..10377e2
--- /dev/null
+++ b/syg-backend/coverage/SYG-rest-controller/syg.controller/index.html
@@ -0,0 +1 @@
+syg.controllersyg.controller
\ No newline at end of file
diff --git a/syg-backend/coverage/SYG-rest-controller/syg.controller/index.source.html b/syg-backend/coverage/SYG-rest-controller/syg.controller/index.source.html
new file mode 100644
index 0000000..b7cc3fc
--- /dev/null
+++ b/syg-backend/coverage/SYG-rest-controller/syg.controller/index.source.html
@@ -0,0 +1 @@
+syg.controllersyg.controller
\ No newline at end of file
diff --git a/syg-backend/coverage/index.html b/syg-backend/coverage/index.html
new file mode 100644
index 0000000..7928d1c
--- /dev/null
+++ b/syg-backend/coverage/index.html
@@ -0,0 +1 @@
+SYG_bootstrapSYG_bootstrap
Element | Missed Instructions | Cov. | Missed Branches | Cov. | Missed | Cxty | Missed | Lines | Missed | Methods | Missed | Classes |
Total | 1,901 of 3,133 | 39% | 303 of 378 | 19% | 251 | 396 | 124 | 334 | 84 | 207 | 1 | 25 |
SYG-mysql-adapter | | 43% | | 26% | 122 | 203 | 43 | 171 | 41 | 102 | 0 | 11 |
SYG-domain | | 27% | | 10% | 127 | 178 | 58 | 102 | 42 | 92 | 1 | 11 |
SYG-rest-controller | | 66% | | 75% | 2 | 15 | 23 | 61 | 1 | 13 | 0 | 3 |
\ No newline at end of file
diff --git a/syg-backend/coverage/jacoco-resources/branchfc.gif b/syg-backend/coverage/jacoco-resources/branchfc.gif
new file mode 100644
index 0000000..989b46d
Binary files /dev/null and b/syg-backend/coverage/jacoco-resources/branchfc.gif differ
diff --git a/syg-backend/coverage/jacoco-resources/branchnc.gif b/syg-backend/coverage/jacoco-resources/branchnc.gif
new file mode 100644
index 0000000..1933e07
Binary files /dev/null and b/syg-backend/coverage/jacoco-resources/branchnc.gif differ
diff --git a/syg-backend/coverage/jacoco-resources/branchpc.gif b/syg-backend/coverage/jacoco-resources/branchpc.gif
new file mode 100644
index 0000000..cbf711b
Binary files /dev/null and b/syg-backend/coverage/jacoco-resources/branchpc.gif differ
diff --git a/syg-backend/coverage/jacoco-resources/bundle.gif b/syg-backend/coverage/jacoco-resources/bundle.gif
new file mode 100644
index 0000000..fca9c53
Binary files /dev/null and b/syg-backend/coverage/jacoco-resources/bundle.gif differ
diff --git a/syg-backend/coverage/jacoco-resources/class.gif b/syg-backend/coverage/jacoco-resources/class.gif
new file mode 100644
index 0000000..eb348fb
Binary files /dev/null and b/syg-backend/coverage/jacoco-resources/class.gif differ
diff --git a/syg-backend/coverage/jacoco-resources/down.gif b/syg-backend/coverage/jacoco-resources/down.gif
new file mode 100644
index 0000000..440a14d
Binary files /dev/null and b/syg-backend/coverage/jacoco-resources/down.gif differ
diff --git a/syg-backend/coverage/jacoco-resources/greenbar.gif b/syg-backend/coverage/jacoco-resources/greenbar.gif
new file mode 100644
index 0000000..0ba6567
Binary files /dev/null and b/syg-backend/coverage/jacoco-resources/greenbar.gif differ
diff --git a/syg-backend/coverage/jacoco-resources/group.gif b/syg-backend/coverage/jacoco-resources/group.gif
new file mode 100644
index 0000000..a4ea580
Binary files /dev/null and b/syg-backend/coverage/jacoco-resources/group.gif differ
diff --git a/syg-backend/coverage/jacoco-resources/method.gif b/syg-backend/coverage/jacoco-resources/method.gif
new file mode 100644
index 0000000..7d24707
Binary files /dev/null and b/syg-backend/coverage/jacoco-resources/method.gif differ
diff --git a/syg-backend/coverage/jacoco-resources/package.gif b/syg-backend/coverage/jacoco-resources/package.gif
new file mode 100644
index 0000000..131c28d
Binary files /dev/null and b/syg-backend/coverage/jacoco-resources/package.gif differ
diff --git a/syg-backend/coverage/jacoco-resources/prettify.css b/syg-backend/coverage/jacoco-resources/prettify.css
new file mode 100644
index 0000000..be5166e
--- /dev/null
+++ b/syg-backend/coverage/jacoco-resources/prettify.css
@@ -0,0 +1,13 @@
+/* Pretty printing styles. Used with prettify.js. */
+
+.str { color: #2A00FF; }
+.kwd { color: #7F0055; font-weight:bold; }
+.com { color: #3F5FBF; }
+.typ { color: #606; }
+.lit { color: #066; }
+.pun { color: #660; }
+.pln { color: #000; }
+.tag { color: #008; }
+.atn { color: #606; }
+.atv { color: #080; }
+.dec { color: #606; }
diff --git a/syg-backend/coverage/jacoco-resources/prettify.js b/syg-backend/coverage/jacoco-resources/prettify.js
new file mode 100644
index 0000000..b2766fe
--- /dev/null
+++ b/syg-backend/coverage/jacoco-resources/prettify.js
@@ -0,0 +1,1510 @@
+// Copyright (C) 2006 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+
+/**
+ * @fileoverview
+ * some functions for browser-side pretty printing of code contained in html.
+ *
+ *
+ * For a fairly comprehensive set of languages see the
+ * README
+ * file that came with this source. At a minimum, the lexer should work on a
+ * number of languages including C and friends, Java, Python, Bash, SQL, HTML,
+ * XML, CSS, Javascript, and Makefiles. It works passably on Ruby, PHP and Awk
+ * and a subset of Perl, but, because of commenting conventions, doesn't work on
+ * Smalltalk, Lisp-like, or CAML-like languages without an explicit lang class.
+ *
+ * Usage:
+ * - include this source file in an html page via
+ * {@code }
+ *
- define style rules. See the example page for examples.
+ *
- mark the {@code
} and {@code } tags in your source with
+ * {@code class=prettyprint.}
+ * You can also use the (html deprecated) {@code } tag, but the pretty
+ * printer needs to do more substantial DOM manipulations to support that, so
+ * some css styles may not be preserved.
+ *
+ * That's it. I wanted to keep the API as simple as possible, so there's no
+ * need to specify which language the code is in, but if you wish, you can add
+ * another class to the {@code } or {@code } element to specify the
+ * language, as in {@code }. Any class that
+ * starts with "lang-" followed by a file extension, specifies the file type.
+ * See the "lang-*.js" files in this directory for code that implements
+ * per-language file handlers.
+ *
+ * Change log:
+ * cbeust, 2006/08/22
+ *
+ * Java annotations (start with "@") are now captured as literals ("lit")
+ *
+ * @requires console
+ */
+
+// JSLint declarations
+/*global console, document, navigator, setTimeout, window */
+
+/**
+ * Split {@code prettyPrint} into multiple timeouts so as not to interfere with
+ * UI events.
+ * If set to {@code false}, {@code prettyPrint()} is synchronous.
+ */
+window['PR_SHOULD_USE_CONTINUATION'] = true;
+
+/** the number of characters between tab columns */
+window['PR_TAB_WIDTH'] = 8;
+
+/** Walks the DOM returning a properly escaped version of innerHTML.
+ * @param {Node} node
+ * @param {Array.} out output buffer that receives chunks of HTML.
+ */
+window['PR_normalizedHtml']
+
+/** Contains functions for creating and registering new language handlers.
+ * @type {Object}
+ */
+ = window['PR']
+
+/** Pretty print a chunk of code.
+ *
+ * @param {string} sourceCodeHtml code as html
+ * @return {string} code as html, but prettier
+ */
+ = window['prettyPrintOne']
+/** Find all the {@code } and {@code } tags in the DOM with
+ * {@code class=prettyprint} and prettify them.
+ * @param {Function?} opt_whenDone if specified, called when the last entry
+ * has been finished.
+ */
+ = window['prettyPrint'] = void 0;
+
+/** browser detection. @extern @returns false if not IE, otherwise the major version. */
+window['_pr_isIE6'] = function () {
+ var ieVersion = navigator && navigator.userAgent &&
+ navigator.userAgent.match(/\bMSIE ([678])\./);
+ ieVersion = ieVersion ? +ieVersion[1] : false;
+ window['_pr_isIE6'] = function () { return ieVersion; };
+ return ieVersion;
+};
+
+
+(function () {
+ // Keyword lists for various languages.
+ var FLOW_CONTROL_KEYWORDS =
+ "break continue do else for if return while ";
+ var C_KEYWORDS = FLOW_CONTROL_KEYWORDS + "auto case char const default " +
+ "double enum extern float goto int long register short signed sizeof " +
+ "static struct switch typedef union unsigned void volatile ";
+ var COMMON_KEYWORDS = C_KEYWORDS + "catch class delete false import " +
+ "new operator private protected public this throw true try typeof ";
+ var CPP_KEYWORDS = COMMON_KEYWORDS + "alignof align_union asm axiom bool " +
+ "concept concept_map const_cast constexpr decltype " +
+ "dynamic_cast explicit export friend inline late_check " +
+ "mutable namespace nullptr reinterpret_cast static_assert static_cast " +
+ "template typeid typename using virtual wchar_t where ";
+ var JAVA_KEYWORDS = COMMON_KEYWORDS +
+ "abstract boolean byte extends final finally implements import " +
+ "instanceof null native package strictfp super synchronized throws " +
+ "transient ";
+ var CSHARP_KEYWORDS = JAVA_KEYWORDS +
+ "as base by checked decimal delegate descending event " +
+ "fixed foreach from group implicit in interface internal into is lock " +
+ "object out override orderby params partial readonly ref sbyte sealed " +
+ "stackalloc string select uint ulong unchecked unsafe ushort var ";
+ var JSCRIPT_KEYWORDS = COMMON_KEYWORDS +
+ "debugger eval export function get null set undefined var with " +
+ "Infinity NaN ";
+ var PERL_KEYWORDS = "caller delete die do dump elsif eval exit foreach for " +
+ "goto if import last local my next no our print package redo require " +
+ "sub undef unless until use wantarray while BEGIN END ";
+ var PYTHON_KEYWORDS = FLOW_CONTROL_KEYWORDS + "and as assert class def del " +
+ "elif except exec finally from global import in is lambda " +
+ "nonlocal not or pass print raise try with yield " +
+ "False True None ";
+ var RUBY_KEYWORDS = FLOW_CONTROL_KEYWORDS + "alias and begin case class def" +
+ " defined elsif end ensure false in module next nil not or redo rescue " +
+ "retry self super then true undef unless until when yield BEGIN END ";
+ var SH_KEYWORDS = FLOW_CONTROL_KEYWORDS + "case done elif esac eval fi " +
+ "function in local set then until ";
+ var ALL_KEYWORDS = (
+ CPP_KEYWORDS + CSHARP_KEYWORDS + JSCRIPT_KEYWORDS + PERL_KEYWORDS +
+ PYTHON_KEYWORDS + RUBY_KEYWORDS + SH_KEYWORDS);
+
+ // token style names. correspond to css classes
+ /** token style for a string literal */
+ var PR_STRING = 'str';
+ /** token style for a keyword */
+ var PR_KEYWORD = 'kwd';
+ /** token style for a comment */
+ var PR_COMMENT = 'com';
+ /** token style for a type */
+ var PR_TYPE = 'typ';
+ /** token style for a literal value. e.g. 1, null, true. */
+ var PR_LITERAL = 'lit';
+ /** token style for a punctuation string. */
+ var PR_PUNCTUATION = 'pun';
+ /** token style for a punctuation string. */
+ var PR_PLAIN = 'pln';
+
+ /** token style for an sgml tag. */
+ var PR_TAG = 'tag';
+ /** token style for a markup declaration such as a DOCTYPE. */
+ var PR_DECLARATION = 'dec';
+ /** token style for embedded source. */
+ var PR_SOURCE = 'src';
+ /** token style for an sgml attribute name. */
+ var PR_ATTRIB_NAME = 'atn';
+ /** token style for an sgml attribute value. */
+ var PR_ATTRIB_VALUE = 'atv';
+
+ /**
+ * A class that indicates a section of markup that is not code, e.g. to allow
+ * embedding of line numbers within code listings.
+ */
+ var PR_NOCODE = 'nocode';
+
+ /** A set of tokens that can precede a regular expression literal in
+ * javascript.
+ * http://www.mozilla.org/js/language/js20/rationale/syntax.html has the full
+ * list, but I've removed ones that might be problematic when seen in
+ * languages that don't support regular expression literals.
+ *
+ * Specifically, I've removed any keywords that can't precede a regexp
+ * literal in a syntactically legal javascript program, and I've removed the
+ * "in" keyword since it's not a keyword in many languages, and might be used
+ * as a count of inches.
+ *
+ *
The link a above does not accurately describe EcmaScript rules since
+ * it fails to distinguish between (a=++/b/i) and (a++/b/i) but it works
+ * very well in practice.
+ *
+ * @private
+ */
+ var REGEXP_PRECEDER_PATTERN = function () {
+ var preceders = [
+ "!", "!=", "!==", "#", "%", "%=", "&", "&&", "&&=",
+ "&=", "(", "*", "*=", /* "+", */ "+=", ",", /* "-", */ "-=",
+ "->", /*".", "..", "...", handled below */ "/", "/=", ":", "::", ";",
+ "<", "<<", "<<=", "<=", "=", "==", "===", ">",
+ ">=", ">>", ">>=", ">>>", ">>>=", "?", "@", "[",
+ "^", "^=", "^^", "^^=", "{", "|", "|=", "||",
+ "||=", "~" /* handles =~ and !~ */,
+ "break", "case", "continue", "delete",
+ "do", "else", "finally", "instanceof",
+ "return", "throw", "try", "typeof"
+ ];
+ var pattern = '(?:^^|[+-]';
+ for (var i = 0; i < preceders.length; ++i) {
+ pattern += '|' + preceders[i].replace(/([^=<>:&a-z])/g, '\\$1');
+ }
+ pattern += ')\\s*'; // matches at end, and matches empty string
+ return pattern;
+ // CAVEAT: this does not properly handle the case where a regular
+ // expression immediately follows another since a regular expression may
+ // have flags for case-sensitivity and the like. Having regexp tokens
+ // adjacent is not valid in any language I'm aware of, so I'm punting.
+ // TODO: maybe style special characters inside a regexp as punctuation.
+ }();
+
+ // Define regexps here so that the interpreter doesn't have to create an
+ // object each time the function containing them is called.
+ // The language spec requires a new object created even if you don't access
+ // the $1 members.
+ var pr_amp = /&/g;
+ var pr_lt = //g;
+ var pr_quot = /\"/g;
+ /** like textToHtml but escapes double quotes to be attribute safe. */
+ function attribToHtml(str) {
+ return str.replace(pr_amp, '&')
+ .replace(pr_lt, '<')
+ .replace(pr_gt, '>')
+ .replace(pr_quot, '"');
+ }
+
+ /** escapest html special characters to html. */
+ function textToHtml(str) {
+ return str.replace(pr_amp, '&')
+ .replace(pr_lt, '<')
+ .replace(pr_gt, '>');
+ }
+
+
+ var pr_ltEnt = /</g;
+ var pr_gtEnt = />/g;
+ var pr_aposEnt = /'/g;
+ var pr_quotEnt = /"/g;
+ var pr_ampEnt = /&/g;
+ var pr_nbspEnt = / /g;
+ /** unescapes html to plain text. */
+ function htmlToText(html) {
+ var pos = html.indexOf('&');
+ if (pos < 0) { return html; }
+ // Handle numeric entities specially. We can't use functional substitution
+ // since that doesn't work in older versions of Safari.
+ // These should be rare since most browsers convert them to normal chars.
+ for (--pos; (pos = html.indexOf('', pos + 1)) >= 0;) {
+ var end = html.indexOf(';', pos);
+ if (end >= 0) {
+ var num = html.substring(pos + 3, end);
+ var radix = 10;
+ if (num && num.charAt(0) === 'x') {
+ num = num.substring(1);
+ radix = 16;
+ }
+ var codePoint = parseInt(num, radix);
+ if (!isNaN(codePoint)) {
+ html = (html.substring(0, pos) + String.fromCharCode(codePoint) +
+ html.substring(end + 1));
+ }
+ }
+ }
+
+ return html.replace(pr_ltEnt, '<')
+ .replace(pr_gtEnt, '>')
+ .replace(pr_aposEnt, "'")
+ .replace(pr_quotEnt, '"')
+ .replace(pr_nbspEnt, ' ')
+ .replace(pr_ampEnt, '&');
+ }
+
+ /** is the given node's innerHTML normally unescaped? */
+ function isRawContent(node) {
+ return 'XMP' === node.tagName;
+ }
+
+ var newlineRe = /[\r\n]/g;
+ /**
+ * Are newlines and adjacent spaces significant in the given node's innerHTML?
+ */
+ function isPreformatted(node, content) {
+ // PRE means preformatted, and is a very common case, so don't create
+ // unnecessary computed style objects.
+ if ('PRE' === node.tagName) { return true; }
+ if (!newlineRe.test(content)) { return true; } // Don't care
+ var whitespace = '';
+ // For disconnected nodes, IE has no currentStyle.
+ if (node.currentStyle) {
+ whitespace = node.currentStyle.whiteSpace;
+ } else if (window.getComputedStyle) {
+ // Firefox makes a best guess if node is disconnected whereas Safari
+ // returns the empty string.
+ whitespace = window.getComputedStyle(node, null).whiteSpace;
+ }
+ return !whitespace || whitespace === 'pre';
+ }
+
+ function normalizedHtml(node, out, opt_sortAttrs) {
+ switch (node.nodeType) {
+ case 1: // an element
+ var name = node.tagName.toLowerCase();
+
+ out.push('<', name);
+ var attrs = node.attributes;
+ var n = attrs.length;
+ if (n) {
+ if (opt_sortAttrs) {
+ var sortedAttrs = [];
+ for (var i = n; --i >= 0;) { sortedAttrs[i] = attrs[i]; }
+ sortedAttrs.sort(function (a, b) {
+ return (a.name < b.name) ? -1 : a.name === b.name ? 0 : 1;
+ });
+ attrs = sortedAttrs;
+ }
+ for (var i = 0; i < n; ++i) {
+ var attr = attrs[i];
+ if (!attr.specified) { continue; }
+ out.push(' ', attr.name.toLowerCase(),
+ '="', attribToHtml(attr.value), '"');
+ }
+ }
+ out.push('>');
+ for (var child = node.firstChild; child; child = child.nextSibling) {
+ normalizedHtml(child, out, opt_sortAttrs);
+ }
+ if (node.firstChild || !/^(?:br|link|img)$/.test(name)) {
+ out.push('<\/', name, '>');
+ }
+ break;
+ case 3: case 4: // text
+ out.push(textToHtml(node.nodeValue));
+ break;
+ }
+ }
+
+ /**
+ * Given a group of {@link RegExp}s, returns a {@code RegExp} that globally
+ * matches the union o the sets o strings matched d by the input RegExp.
+ * Since it matches globally, if the input strings have a start-of-input
+ * anchor (/^.../), it is ignored for the purposes of unioning.
+ * @param {Array.} regexs non multiline, non-global regexs.
+ * @return {RegExp} a global regex.
+ */
+ function combinePrefixPatterns(regexs) {
+ var capturedGroupIndex = 0;
+
+ var needToFoldCase = false;
+ var ignoreCase = false;
+ for (var i = 0, n = regexs.length; i < n; ++i) {
+ var regex = regexs[i];
+ if (regex.ignoreCase) {
+ ignoreCase = true;
+ } else if (/[a-z]/i.test(regex.source.replace(
+ /\\u[0-9a-f]{4}|\\x[0-9a-f]{2}|\\[^ux]/gi, ''))) {
+ needToFoldCase = true;
+ ignoreCase = false;
+ break;
+ }
+ }
+
+ function decodeEscape(charsetPart) {
+ if (charsetPart.charAt(0) !== '\\') { return charsetPart.charCodeAt(0); }
+ switch (charsetPart.charAt(1)) {
+ case 'b': return 8;
+ case 't': return 9;
+ case 'n': return 0xa;
+ case 'v': return 0xb;
+ case 'f': return 0xc;
+ case 'r': return 0xd;
+ case 'u': case 'x':
+ return parseInt(charsetPart.substring(2), 16)
+ || charsetPart.charCodeAt(1);
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7':
+ return parseInt(charsetPart.substring(1), 8);
+ default: return charsetPart.charCodeAt(1);
+ }
+ }
+
+ function encodeEscape(charCode) {
+ if (charCode < 0x20) {
+ return (charCode < 0x10 ? '\\x0' : '\\x') + charCode.toString(16);
+ }
+ var ch = String.fromCharCode(charCode);
+ if (ch === '\\' || ch === '-' || ch === '[' || ch === ']') {
+ ch = '\\' + ch;
+ }
+ return ch;
+ }
+
+ function caseFoldCharset(charSet) {
+ var charsetParts = charSet.substring(1, charSet.length - 1).match(
+ new RegExp(
+ '\\\\u[0-9A-Fa-f]{4}'
+ + '|\\\\x[0-9A-Fa-f]{2}'
+ + '|\\\\[0-3][0-7]{0,2}'
+ + '|\\\\[0-7]{1,2}'
+ + '|\\\\[\\s\\S]'
+ + '|-'
+ + '|[^-\\\\]',
+ 'g'));
+ var groups = [];
+ var ranges = [];
+ var inverse = charsetParts[0] === '^';
+ for (var i = inverse ? 1 : 0, n = charsetParts.length; i < n; ++i) {
+ var p = charsetParts[i];
+ switch (p) {
+ case '\\B': case '\\b':
+ case '\\D': case '\\d':
+ case '\\S': case '\\s':
+ case '\\W': case '\\w':
+ groups.push(p);
+ continue;
+ }
+ var start = decodeEscape(p);
+ var end;
+ if (i + 2 < n && '-' === charsetParts[i + 1]) {
+ end = decodeEscape(charsetParts[i + 2]);
+ i += 2;
+ } else {
+ end = start;
+ }
+ ranges.push([start, end]);
+ // If the range might intersect letters, then expand it.
+ if (!(end < 65 || start > 122)) {
+ if (!(end < 65 || start > 90)) {
+ ranges.push([Math.max(65, start) | 32, Math.min(end, 90) | 32]);
+ }
+ if (!(end < 97 || start > 122)) {
+ ranges.push([Math.max(97, start) & ~32, Math.min(end, 122) & ~32]);
+ }
+ }
+ }
+
+ // [[1, 10], [3, 4], [8, 12], [14, 14], [16, 16], [17, 17]]
+ // -> [[1, 12], [14, 14], [16, 17]]
+ ranges.sort(function (a, b) { return (a[0] - b[0]) || (b[1] - a[1]); });
+ var consolidatedRanges = [];
+ var lastRange = [NaN, NaN];
+ for (var i = 0; i < ranges.length; ++i) {
+ var range = ranges[i];
+ if (range[0] <= lastRange[1] + 1) {
+ lastRange[1] = Math.max(lastRange[1], range[1]);
+ } else {
+ consolidatedRanges.push(lastRange = range);
+ }
+ }
+
+ var out = ['['];
+ if (inverse) { out.push('^'); }
+ out.push.apply(out, groups);
+ for (var i = 0; i < consolidatedRanges.length; ++i) {
+ var range = consolidatedRanges[i];
+ out.push(encodeEscape(range[0]));
+ if (range[1] > range[0]) {
+ if (range[1] + 1 > range[0]) { out.push('-'); }
+ out.push(encodeEscape(range[1]));
+ }
+ }
+ out.push(']');
+ return out.join('');
+ }
+
+ function allowAnywhereFoldCaseAndRenumberGroups(regex) {
+ // Split into character sets, escape sequences, punctuation strings
+ // like ('(', '(?:', ')', '^'), and runs of characters that do not
+ // include any of the above.
+ var parts = regex.source.match(
+ new RegExp(
+ '(?:'
+ + '\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]' // a character set
+ + '|\\\\u[A-Fa-f0-9]{4}' // a unicode escape
+ + '|\\\\x[A-Fa-f0-9]{2}' // a hex escape
+ + '|\\\\[0-9]+' // a back-reference or octal escape
+ + '|\\\\[^ux0-9]' // other escape sequence
+ + '|\\(\\?[:!=]' // start of a non-capturing group
+ + '|[\\(\\)\\^]' // start/emd of a group, or line start
+ + '|[^\\x5B\\x5C\\(\\)\\^]+' // run of other characters
+ + ')',
+ 'g'));
+ var n = parts.length;
+
+ // Maps captured group numbers to the number they will occupy in
+ // the output or to -1 if that has not been determined, or to
+ // undefined if they need not be capturing in the output.
+ var capturedGroups = [];
+
+ // Walk over and identify back references to build the capturedGroups
+ // mapping.
+ for (var i = 0, groupIndex = 0; i < n; ++i) {
+ var p = parts[i];
+ if (p === '(') {
+ // groups are 1-indexed, so max group index is count of '('
+ ++groupIndex;
+ } else if ('\\' === p.charAt(0)) {
+ var decimalValue = +p.substring(1);
+ if (decimalValue && decimalValue <= groupIndex) {
+ capturedGroups[decimalValue] = -1;
+ }
+ }
+ }
+
+ // Renumber groups and reduce capturing groups to non-capturing groups
+ // where possible.
+ for (var i = 1; i < capturedGroups.length; ++i) {
+ if (-1 === capturedGroups[i]) {
+ capturedGroups[i] = ++capturedGroupIndex;
+ }
+ }
+ for (var i = 0, groupIndex = 0; i < n; ++i) {
+ var p = parts[i];
+ if (p === '(') {
+ ++groupIndex;
+ if (capturedGroups[groupIndex] === undefined) {
+ parts[i] = '(?:';
+ }
+ } else if ('\\' === p.charAt(0)) {
+ var decimalValue = +p.substring(1);
+ if (decimalValue && decimalValue <= groupIndex) {
+ parts[i] = '\\' + capturedGroups[groupIndex];
+ }
+ }
+ }
+
+ // Remove any prefix anchors so that the output will match anywhere.
+ // ^^ really does mean an anchored match though.
+ for (var i = 0, groupIndex = 0; i < n; ++i) {
+ if ('^' === parts[i] && '^' !== parts[i + 1]) { parts[i] = ''; }
+ }
+
+ // Expand letters to groupts to handle mixing of case-sensitive and
+ // case-insensitive patterns if necessary.
+ if (regex.ignoreCase && needToFoldCase) {
+ for (var i = 0; i < n; ++i) {
+ var p = parts[i];
+ var ch0 = p.charAt(0);
+ if (p.length >= 2 && ch0 === '[') {
+ parts[i] = caseFoldCharset(p);
+ } else if (ch0 !== '\\') {
+ // TODO: handle letters in numeric escapes.
+ parts[i] = p.replace(
+ /[a-zA-Z]/g,
+ function (ch) {
+ var cc = ch.charCodeAt(0);
+ return '[' + String.fromCharCode(cc & ~32, cc | 32) + ']';
+ });
+ }
+ }
+ }
+
+ return parts.join('');
+ }
+
+ var rewritten = [];
+ for (var i = 0, n = regexs.length; i < n; ++i) {
+ var regex = regexs[i];
+ if (regex.global || regex.multiline) { throw new Error('' + regex); }
+ rewritten.push(
+ '(?:' + allowAnywhereFoldCaseAndRenumberGroups(regex) + ')');
+ }
+
+ return new RegExp(rewritten.join('|'), ignoreCase ? 'gi' : 'g');
+ }
+
+ var PR_innerHtmlWorks = null;
+ function getInnerHtml(node) {
+ // inner html is hopelessly broken in Safari 2.0.4 when the content is
+ // an html description of well formed XML and the containing tag is a PRE
+ // tag, so we detect that case and emulate innerHTML.
+ if (null === PR_innerHtmlWorks) {
+ var testNode = document.createElement('PRE');
+ testNode.appendChild(
+ document.createTextNode('\n'));
+ PR_innerHtmlWorks = !/)[\r\n]+/g, '$1')
+ .replace(/(?:[\r\n]+[ \t]*)+/g, ' ');
+ }
+ return content;
+ }
+
+ var out = [];
+ for (var child = node.firstChild; child; child = child.nextSibling) {
+ normalizedHtml(child, out);
+ }
+ return out.join('');
+ }
+
+ /** returns a function that expand tabs to spaces. This function can be fed
+ * successive chunks of text, and will maintain its own internal state to
+ * keep track of how tabs are expanded.
+ * @return {function (string) : string} a function that takes
+ * plain text and return the text with tabs expanded.
+ * @private
+ */
+ function makeTabExpander(tabWidth) {
+ var SPACES = ' ';
+ var charInLine = 0;
+
+ return function (plainText) {
+ // walk over each character looking for tabs and newlines.
+ // On tabs, expand them. On newlines, reset charInLine.
+ // Otherwise increment charInLine
+ var out = null;
+ var pos = 0;
+ for (var i = 0, n = plainText.length; i < n; ++i) {
+ var ch = plainText.charAt(i);
+
+ switch (ch) {
+ case '\t':
+ if (!out) { out = []; }
+ out.push(plainText.substring(pos, i));
+ // calculate how much space we need in front of this part
+ // nSpaces is the amount of padding -- the number of spaces needed
+ // to move us to the next column, where columns occur at factors of
+ // tabWidth.
+ var nSpaces = tabWidth - (charInLine % tabWidth);
+ charInLine += nSpaces;
+ for (; nSpaces >= 0; nSpaces -= SPACES.length) {
+ out.push(SPACES.substring(0, nSpaces));
+ }
+ pos = i + 1;
+ break;
+ case '\n':
+ charInLine = 0;
+ break;
+ default:
+ ++charInLine;
+ }
+ }
+ if (!out) { return plainText; }
+ out.push(plainText.substring(pos));
+ return out.join('');
+ };
+ }
+
+ var pr_chunkPattern = new RegExp(
+ '[^<]+' // A run of characters other than '<'
+ + '|<\!--[\\s\\S]*?--\>' // an HTML comment
+ + '|' // a CDATA section
+ // a probable tag that should not be highlighted
+ + '|<\/?[a-zA-Z](?:[^>\"\']|\'[^\']*\'|\"[^\"]*\")*>'
+ + '|<', // A '<' that does not begin a larger chunk
+ 'g');
+ var pr_commentPrefix = /^<\!--/;
+ var pr_cdataPrefix = /^) into their textual equivalent.
+ *
+ * @param {string} s html where whitespace is considered significant.
+ * @return {Object} source code and extracted tags.
+ * @private
+ */
+ function extractTags(s) {
+ // since the pattern has the 'g' modifier and defines no capturing groups,
+ // this will return a list of all chunks which we then classify and wrap as
+ // PR_Tokens
+ var matches = s.match(pr_chunkPattern);
+ var sourceBuf = [];
+ var sourceBufLen = 0;
+ var extractedTags = [];
+ if (matches) {
+ for (var i = 0, n = matches.length; i < n; ++i) {
+ var match = matches[i];
+ if (match.length > 1 && match.charAt(0) === '<') {
+ if (pr_commentPrefix.test(match)) { continue; }
+ if (pr_cdataPrefix.test(match)) {
+ // strip CDATA prefix and suffix. Don't unescape since it's CDATA
+ sourceBuf.push(match.substring(9, match.length - 3));
+ sourceBufLen += match.length - 12;
+ } else if (pr_brPrefix.test(match)) {
+ //
tags are lexically significant so convert them to text.
+ // This is undone later.
+ sourceBuf.push('\n');
+ ++sourceBufLen;
+ } else {
+ if (match.indexOf(PR_NOCODE) >= 0 && isNoCodeTag(match)) {
+ // A will start a section that should be
+ // ignored. Continue walking the list until we see a matching end
+ // tag.
+ var name = match.match(pr_tagNameRe)[2];
+ var depth = 1;
+ var j;
+ end_tag_loop:
+ for (j = i + 1; j < n; ++j) {
+ var name2 = matches[j].match(pr_tagNameRe);
+ if (name2 && name2[2] === name) {
+ if (name2[1] === '/') {
+ if (--depth === 0) { break end_tag_loop; }
+ } else {
+ ++depth;
+ }
+ }
+ }
+ if (j < n) {
+ extractedTags.push(
+ sourceBufLen, matches.slice(i, j + 1).join(''));
+ i = j;
+ } else { // Ignore unclosed sections.
+ extractedTags.push(sourceBufLen, match);
+ }
+ } else {
+ extractedTags.push(sourceBufLen, match);
+ }
+ }
+ } else {
+ var literalText = htmlToText(match);
+ sourceBuf.push(literalText);
+ sourceBufLen += literalText.length;
+ }
+ }
+ }
+ return { source: sourceBuf.join(''), tags: extractedTags };
+ }
+
+ /** True if the given tag contains a class attribute with the nocode class. */
+ function isNoCodeTag(tag) {
+ return !!tag
+ // First canonicalize the representation of attributes
+ .replace(/\s(\w+)\s*=\s*(?:\"([^\"]*)\"|'([^\']*)'|(\S+))/g,
+ ' $1="$2$3$4"')
+ // Then look for the attribute we want.
+ .match(/[cC][lL][aA][sS][sS]=\"[^\"]*\bnocode\b/);
+ }
+
+ /**
+ * Apply the given language handler to sourceCode and add the resulting
+ * decorations to out.
+ * @param {number} basePos the index of sourceCode within the chunk of source
+ * whose decorations are already present on out.
+ */
+ function appendDecorations(basePos, sourceCode, langHandler, out) {
+ if (!sourceCode) { return; }
+ var job = {
+ source: sourceCode,
+ basePos: basePos
+ };
+ langHandler(job);
+ out.push.apply(out, job.decorations);
+ }
+
+ /** Given triples of [style, pattern, context] returns a lexing function,
+ * The lexing function interprets the patterns to find token boundaries and
+ * returns a decoration list of the form
+ * [index_0, style_0, index_1, style_1, ..., index_n, style_n]
+ * where index_n is an index into the sourceCode, and style_n is a style
+ * constant like PR_PLAIN. index_n-1 <= index_n, and style_n-1 applies to
+ * all characters in sourceCode[index_n-1:index_n].
+ *
+ * The stylePatterns is a list whose elements have the form
+ * [style : string, pattern : RegExp, DEPRECATED, shortcut : string].
+ *
+ * Style is a style constant like PR_PLAIN, or can be a string of the
+ * form 'lang-FOO', where FOO is a language extension describing the
+ * language of the portion of the token in $1 after pattern executes.
+ * E.g., if style is 'lang-lisp', and group 1 contains the text
+ * '(hello (world))', then that portion of the token will be passed to the
+ * registered lisp handler for formatting.
+ * The text before and after group 1 will be restyled using this decorator
+ * so decorators should take care that this doesn't result in infinite
+ * recursion. For example, the HTML lexer rule for SCRIPT elements looks
+ * something like ['lang-js', /<[s]cript>(.+?)<\/script>/]. This may match
+ * '