Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusBernalBermudez committed Sep 15, 2023
1 parent 5bd8894 commit 4cc08d8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 30 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
### Estado del código
[![DevOps](https://github.com/miw-upm/iwvg-devops/actions/workflows/test-sonar.yml/badge.svg)](https://github.com/miw-upm/iwvg-devops/actions/workflows/test-sonar.yml)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=es.upm.miw%3Aiwvg-devops&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=es.upm.miw%3Aiwvg-devops)
[![Heroku broken](https://iwvg-devops.herokuapp.com/system/version-badge)](https://iwvg-devops.herokuapp.com/swagger-ui.html)

### Tecnologías necesarias
`Java` `Maven` `GitHub` `GitHub Actions` `Sonarcloud` `Slack` `Spring-boot` `Railway` `OpenAPI`
Expand Down Expand Up @@ -40,7 +39,7 @@
> Todo el software deberá estar en ingles.
#### 1. Crear un proyecto (**0.5 pto**)
Crear un proyecto Maven llamado: **iwvg-devops-apellido-nombre**, versión **3.0.0**. Para ello se aporta **zip** de la
Crear un proyecto Maven llamado: **iwvg-devops-apellido-nombre**, versión **4.0.0**. Para ello se aporta **zip** de la
plantilla.
> Recordar editar el pom y cambiar el nombre del artefacto (artifactId).
> Recordar cambiar el nombre de la carpeta.
Expand All @@ -51,15 +50,14 @@ plantilla.
> Crear un proyecto de gestión en GitHub y prepararlo para la metodología de Scrum (columnas, etiquetas, hitos...).
#### 3. Sprint 1. Preparación del ecosistema (**1.5 ptos**)
Se crearán las siguientes 4 historias (**Issues**) pero se trabajarán en las ramas **develop** & **master**.
Se crearán las siguientes 2 historias (**Issues**) pero se trabajarán en las ramas **develop** & **master**.

* :one: Integración continua con **GitHub Actions**. Incluir **Badge** en README con **link**.
* :two: Análisis del código con **Sonarcloud**. Incluir **Badge** en README con **link** a la cuenta de Sonar.
* :three: Desplegar en **Heroku**. Incluir **Badge** en README con **link** a la página de **swagger-ui.html**.
> :one:, :two:... representa el orden temporal de desarrollo de los issues.
#### 4. Release (**0.5 pto**)
> Realizar la primera liberación del código (_**v.3.0.0-release**_)
> Realizar la primera liberación del código (_**v.4.0.0-release**_)
#### 5. Sprint 2. Preparación del software a desarrollar (**2 ptos**)
Se crearán las siguientes 4 historias (**Issues**).
Expand All @@ -70,7 +68,7 @@ Se crearán las siguientes 4 historias (**Issues**).

> :one:, :two:... representa el orden temporal de desarrollo de los issues. Cuando un issue se termine se debe incorporar a la rama **develop**. Las clases User, Fraction y UsersDatabase se podrán copiar de las dadas en clase.
> Realizar la segunda liberación del código (_**v.3.1.0-release**_)
> Realizar la segunda liberación del código (_**v.4.1.0-release**_)
#### 6. Sprint 3. Preparación de cuatro búsquedas a partir de las siguientes, según el valor de las primeros cuatro valores distintos del último commit realizado de la liberación anterior, se creará una historia (**
Issues**) por cada búsqueda, con el test correspondiente (**3.5 ptos**).
Expand All @@ -92,10 +90,10 @@ Issues**) por cada búsqueda, con el test correspondiente (**3.5 ptos**).
* `e` Fraction findFractionAdditionByUserId(String id);
* `f` Fraction findFractionSubtractionByUserName(String name);

> Realizar la tercera liberación del código (_**v.3.2.0-release**_)
> Realizar la tercera liberación del código (_**v.4.2.0-release**_)
#### 7. Bug (**1.5 ptos**)
> Suponer que la búsqueda 3 anterior no es buena y se debe proceder a modificarla. Realizar un cambio y proceder a la cuarta liberación del código (_**v.3.2.1-release**_).
> Suponer que la búsqueda 3 anterior no es buena y se debe proceder a modificarla. Realizar un cambio y proceder a la cuarta liberación del código (_**v.4.2.1-release**_).
### :white_check_mark: Criterios transversales **con pérdida de puntos por falta de calidad**
* Uso correcto del flujo de trabajo ramificado. **Hasta -3 ptos**.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class DecimalCollectionWithStream {

private List<Double> collection; // Error: Stream<Double>, un solo uso
private final List<Double> collection; // Error: Stream<Double>, un solo uso

public DecimalCollectionWithStream() {
this.collection = new ArrayList<>();
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/es/upm/miw/iwvg_devops/code/Flow.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import org.apache.logging.log4j.LogManager;

import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Flow {

public Stream<String> streamFromList() {
return Arrays.asList("0", "1", "2").stream();
return Stream.of("0", "1", "2");
}

public IntStream streamFromRange() {
Expand All @@ -36,7 +34,7 @@ public Stream<Integer> streamFromIterate(long limit) {
}

public List<Integer> toList(Stream<Integer> stream) {
return stream.collect(Collectors.toList());
return stream.toList();
}

public Integer[] toArray(Stream<Integer> stream) {
Expand All @@ -59,8 +57,8 @@ public Stream<Integer> removeCopy(Stream<Integer> stream) {
return stream.distinct();
}

public Stream<String> debug(Stream<String> stream) {
return stream.peek(LogManager.getLogger(this.getClass())::debug);
public void debug(Stream<String> stream) {
stream.forEach(LogManager.getLogger(this.getClass())::debug);
}

public Stream<String> mapToString(Stream<Integer> stream) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/es/upm/miw/iwvg_devops/code/Fraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
* medios. Invertir fraccion
*/
public class Fraction {

private int numerator;

private int denominator;

public Fraction(int numerator, int denominator) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/es/upm/miw/iwvg_devops/code/Searches.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.logging.log4j.LogManager;

import java.util.Objects;
import java.util.stream.Stream;

public class Searches {
Expand All @@ -15,11 +16,9 @@ public Stream<String> findUserFamilyNameByUserNameDistinct(String userName) {

public Stream<Integer> findFractionNumeratorByUserFamilyName(String userFamilyName) {
return new UsersDatabase().findAll()
.peek(x -> LogManager.getLogger(this.getClass()).info("before: " + x))
.filter(user -> userFamilyName.equals(user.getFamilyName()))
.peek(x -> LogManager.getLogger(this.getClass()).info("after: " + x))
.flatMap(user -> user.getFractions().stream()
.filter(i -> null != i)
.filter(Objects::nonNull)
)
.map(Fraction::getNumerator);
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/es/upm/miw/iwvg_devops/code/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
import java.util.List;

public class User {

private String id;

private String name;

private String familyName;

private List<Fraction> fractions;

public User() {
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/es/upm/miw/iwvg_devops/code/FlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void testToArray() {
@Test
void testFilterPositive() {
Stream< Integer > stream = Stream.of(-2, 1, 0, -3, 3);
assertEquals(Arrays.asList(1, 0, 3), new Flow().filterPositives(stream).collect(Collectors.toList()));
assertEquals(Arrays.asList(1, 0, 3), new Flow().filterPositives(stream).toList());
}

@Test
Expand All @@ -70,22 +70,22 @@ void testSize() {
@Test
void testRemoveCopy() {
Stream< Integer > stream = Stream.of(0, 1, 0, 2, 2, 0);
assertEquals(Arrays.asList(0, 1, 2), new Flow().removeCopy(stream).collect(Collectors.toList()));
assertEquals(Arrays.asList(0, 1, 2), new Flow().removeCopy(stream).toList());
}

@Test
void testDebug() {
assertEquals(2, new Flow().debug(Stream.of("0", "1")).count());
new Flow().debug(Stream.of("0", "1"));
}

@Test
void testMapToString() {
assertEquals(Arrays.asList("3", "7"), new Flow().mapToString(Stream.of(3, 7)).collect(Collectors.toList()));
assertEquals(Arrays.asList("3", "7"), new Flow().mapToString(Stream.of(3, 7)).toList());
}

@Test
void testIncrement() {
assertEquals(Arrays.asList(4, 8), new Flow().increment(Stream.of(3, 7)).collect(Collectors.toList()));
assertEquals(Arrays.asList(4, 8), new Flow().increment(Stream.of(3, 7)).toList());
}

@Test
Expand All @@ -94,7 +94,7 @@ void testFlatten() {
Integer[] array2 = new Integer[]{0, 3};
Integer[] array3 = new Integer[]{2, 5};
Stream< Integer > stream = new Flow().flatten(Stream.of(array1, array2, array3));
assertEquals(Arrays.asList(0, 1, 0, 3, 2, 5), stream.collect(Collectors.toList()));
assertEquals(Arrays.asList(0, 1, 0, 3, 2, 5), stream.toList());
}

@Test
Expand Down

0 comments on commit 4cc08d8

Please sign in to comment.