Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Pull Request Mitzy #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion ANSWERS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
# Challenge answers

## A - The entities
- I modify pom to add liquibase (https://www.liquibase.org/) dependency and the uml model image (ford-uml.png).

## B - Ingest the data
- I add a property to load a couple of brands, besides of create the need it services to process the DTOs
based on the XML file.
- Add the util class JacksonXmlDataConvert to convert XML file data to DTOs

## C - Expose data with a RESTful API
- Added Jackson annotation to support bidirectional relationships and get the entity as a json object

## D - Adding images
*Option 1: To manage the files in database, first will add a column with type CLOB or BLOB in the SubModel table,
and assign a filename according to a pattern given by the SubModel, like name-line, and limit the type of file extension
(.jpg, .png, .jpeg, etc), and add a few properties for restriction as limit the size of file.

## E - Improvements
*Option 2: Add a column in SubModel table to refer a URL where the file is saved in a storage in cloud
like Amazon Simple Storage Service (Amazon S3).

## E - Improvements
- Add some validation for value column as Model.Type where the values are constant.
- Add other REST services to have CRUDs of the left entities.
- Add Swagger API for document the REST services.
- Add a few Views as Welcome Page and other to manage information.
- Add log configuration to manage the different types to see in console (DEBUG,TRACE, etc).
- Add profile configuration to handle a Development and Production version for compilation.
- Add SonarQube configuration to ensure code quality.
Binary file added cars/ford-uml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions cars/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<properties>
<java.version>1.8</java.version>
<diffChangeLogFile>src/main/resources/db/changelog/db.changelog-master.yaml</diffChangeLogFile>
</properties>

<dependencies>
Expand Down Expand Up @@ -49,6 +50,25 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand All @@ -57,6 +77,27 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.6.3</version>
<configuration>
<diffChangeLogFile>${diffChangeLogFile}</diffChangeLogFile>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mooveit.cars.configurations;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Component
@ConfigurationProperties(prefix="load-data")
public class LoadDataConfiguration {

private String file;
private String brandName;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mooveit.cars.controllers;

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 com.mooveit.cars.service.SubModelService;

@RestController
@RequestMapping("/cars")
public class SubModelController {

private final SubModelService modelService;

public SubModelController(SubModelService modelService) {
super();
this.modelService = modelService;
}

@GetMapping("/by_id")
public Object getCarModelById(@RequestParam(value = "id", defaultValue = "0") Integer id) {
return modelService.getModelById(id);
}

@GetMapping("/by_brand")
public Object getCarsByBrand (@RequestParam(value = "brandName") String brandName) {
return modelService.getAllModelsByBrandName(brandName);
}

}
41 changes: 41 additions & 0 deletions cars/src/main/java/com/mooveit/cars/domain/BaseModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.mooveit.cars.domain;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;

@Data
@NoArgsConstructor
@MappedSuperclass
public class BaseModel {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer idModel;

private @NonNull String name;

private String fromYear;

private String toYear;

@Column(columnDefinition = "boolean default true")
private boolean active;

@ManyToOne
@JoinColumn (name = "wheel")
private @NonNull Wheel wheel;

@ManyToOne
@JoinColumn (name = "engine")
private @NonNull Engine engine;

}
29 changes: 29 additions & 0 deletions cars/src/main/java/com/mooveit/cars/domain/Brand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mooveit.cars.domain;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import com.fasterxml.jackson.annotation.JsonBackReference;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;

@Data
@NoArgsConstructor
@Entity
public class Brand {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer idBrand;
private @NonNull String name;
@JsonBackReference
@OneToMany
private Set<Model> model;
}
31 changes: 31 additions & 0 deletions cars/src/main/java/com/mooveit/cars/domain/Engine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mooveit.cars.domain;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;

@Data
@NoArgsConstructor
@Entity
public class Engine {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer idEngine;

private @NonNull Integer power;

private @NonNull String type;

public Engine(@NonNull Integer power, @NonNull String type) {
super();
this.power = power;
this.type = type;
}

}
32 changes: 32 additions & 0 deletions cars/src/main/java/com/mooveit/cars/domain/Model.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mooveit.cars.domain;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper=false)
@Entity
public class Model extends BaseModel{

@JsonManagedReference
@ManyToOne
@JoinColumn (name = "brand")
private @NonNull Brand brand;
private @NonNull String type;
@JsonBackReference
@OneToMany
private Set<SubModel> subModels;
}
26 changes: 26 additions & 0 deletions cars/src/main/java/com/mooveit/cars/domain/SubModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mooveit.cars.domain;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.fasterxml.jackson.annotation.JsonManagedReference;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper=false)
@Entity
public class SubModel extends BaseModel {

@JsonManagedReference
@ManyToOne
@JoinColumn (name = "model")
private @NonNull Model model;

private String line;
}
31 changes: 31 additions & 0 deletions cars/src/main/java/com/mooveit/cars/domain/Wheel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.mooveit.cars.domain;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;

@Data
@NoArgsConstructor
@Entity
public class Wheel {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer idWheel;

private @NonNull String size;

private @NonNull String type;

public Wheel(@NonNull String size, @NonNull String type) {
super();
this.size = size;
this.type = type;
}

}
22 changes: 22 additions & 0 deletions cars/src/main/java/com/mooveit/cars/dto/CatalogueDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mooveit.cars.dto;

import java.util.List;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@JacksonXmlRootElement(localName = "CATALOGUE")
public class CatalogueDTO {

@JacksonXmlProperty(localName = "MODEL")
@JacksonXmlElementWrapper(useWrapping = false)
private List<ModelDTO> model;
}
23 changes: 23 additions & 0 deletions cars/src/main/java/com/mooveit/cars/dto/DefaultMessageDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mooveit.cars.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@NoArgsConstructor
@Getter
@Setter
@ToString
public class DefaultMessageDTO {

private String message;
private boolean error;

public DefaultMessageDTO(String message, boolean error) {
super();
this.message = message;
this.error = error;
}

}
Loading