Ajout de tests
This commit is contained in:
parent
02588ae2f1
commit
dd480d72c0
|
@ -9,5 +9,6 @@
|
|||
/build/
|
||||
/logs/
|
||||
/workdir/
|
||||
/dokka/
|
||||
|
||||
/src/main/resources/angular/static/*
|
||||
|
|
Binary file not shown.
|
@ -4,8 +4,8 @@ description = "Color Recipes Explorer"
|
|||
|
||||
plugins {
|
||||
id("java")
|
||||
id("org.jetbrains.kotlin.jvm") version "1.4.0"
|
||||
id("org.jetbrains.dokka") version "1.4.0-rc"
|
||||
id("org.jetbrains.kotlin.jvm") version "1.4.10"
|
||||
id("org.jetbrains.dokka") version "1.4.10"
|
||||
id("com.leobia.gradle.sassjavacompiler") version "0.2.1"
|
||||
id("io.freefair.lombok") version "5.2.1"
|
||||
id("org.springframework.boot") version "2.3.4.RELEASE"
|
||||
|
@ -19,12 +19,16 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.4.10"))
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.4.10")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.3")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
|
||||
implementation("javax.xml.bind:jaxb-api:2.3.0")
|
||||
implementation("io.jsonwebtoken:jjwt:0.9.1")
|
||||
implementation("org.apache.poi:poi-ooxml:4.1.0")
|
||||
implementation("org.apache.pdfbox:pdfbox:2.0.4")
|
||||
implementation("com.atlassian.commonmark:commonmark:0.13.1")
|
||||
implementation("commons-io:commons-io:2.6")
|
||||
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.3.4.RELEASE")
|
||||
implementation("org.springframework.boot:spring-boot-starter-jdbc:2.3.4.RELEASE")
|
||||
|
@ -33,28 +37,35 @@ dependencies {
|
|||
implementation("org.springframework.boot:spring-boot-starter-validation:2.3.4.RELEASE")
|
||||
implementation("org.springframework.boot:spring-boot-starter-security:2.3.4.RELEASE")
|
||||
implementation("org.springframework.boot:spring-boot-configuration-processor:2.3.4.RELEASE")
|
||||
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test:2.3.4.RELEASE")
|
||||
testImplementation("org.springframework.boot:spring-boot-test-autoconfigure:2.3.4.RELEASE")
|
||||
implementation("org.springframework.boot:spring-boot-devtools:2.3.4.RELEASE")
|
||||
|
||||
implementation("javax.xml.bind:jaxb-api:2.3.0")
|
||||
implementation("io.jsonwebtoken:jjwt:0.9.1")
|
||||
implementation("org.apache.poi:poi-ooxml:4.1.0")
|
||||
implementation("org.apache.pdfbox:pdfbox:2.0.4")
|
||||
implementation("com.atlassian.commonmark:commonmark:0.13.1")
|
||||
implementation("commons-io:commons-io:2.6")
|
||||
implementation("org.springframework:spring-test:5.1.6.RELEASE")
|
||||
implementation("org.mockito:mockito-core:2.23.4")
|
||||
implementation("org.junit.jupiter:junit-jupiter-api:5.3.2")
|
||||
testImplementation("org.springframework:spring-test:5.1.6.RELEASE")
|
||||
testImplementation("org.mockito:mockito-core:3.6.0")
|
||||
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.2")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test:2.3.4.RELEASE")
|
||||
testImplementation("org.springframework.boot:spring-boot-test-autoconfigure:2.3.4.RELEASE")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test:1.4.10")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.4.10")
|
||||
// testImplementation("io.mockk:mockk:1.10.2")
|
||||
|
||||
runtimeOnly("com.h2database:h2:1.4.199")
|
||||
compileOnly("org.projectlombok:lombok:1.18.10")
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
sourceCompatibility = JavaVersion.VERSION_14
|
||||
targetCompatibility = JavaVersion.VERSION_14
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java
|
||||
kotlin
|
||||
}
|
||||
test {
|
||||
kotlin
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("buildFrontend") {
|
||||
|
@ -85,13 +96,13 @@ tasks.test {
|
|||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.compilerArgs.addAll(arrayOf("--release", "11"))
|
||||
options.compilerArgs.addAll(arrayOf("--release", "14"))
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "11"
|
||||
kotlinOptions.jvmTarget = "14"
|
||||
}
|
||||
|
||||
tasks.dokkaHtml {
|
||||
outputDirectory = "$buildDir/dokka"
|
||||
outputDirectory.set(rootDir.resolve("dokka"))
|
||||
}
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {Routes, RouterModule} from '@angular/router';
|
||||
|
||||
|
||||
const routes: Routes = [{ path: 'color', loadChildren: () => import('./modules/colors/colors.module').then(m => m.ColorsModule) }, { path: 'account', loadChildren: () => import('./modules/accounts/accounts.module').then(m => m.AccountsModule) }, { path: 'employee', loadChildren: () => import('./modules/employees/employees.module').then(m => m.EmployeesModule) }, { path: 'group', loadChildren: () => import('./modules/groups/groups.module').then(m => m.GroupsModule) }];
|
||||
const routes: Routes = [{
|
||||
path: 'color',
|
||||
loadChildren: () => import('./modules/colors/colors.module').then(m => m.ColorsModule)
|
||||
}, {
|
||||
path: 'account',
|
||||
loadChildren: () => import('./modules/accounts/accounts.module').then(m => m.AccountsModule)
|
||||
}, {
|
||||
path: 'employee',
|
||||
loadChildren: () => import('./modules/employees/employees.module').then(m => m.EmployeesModule)
|
||||
}, {
|
||||
path: 'group',
|
||||
loadChildren: () => import('./modules/groups/groups.module').then(m => m.GroupsModule)
|
||||
}, {
|
||||
path: 'inventory',
|
||||
loadChildren: () => import('./modules/inventory/inventory.module').then(m => m.InventoryModule)
|
||||
}];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forRoot(routes)],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class AppRoutingModule { }
|
||||
export class AppRoutingModule {
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import {NgModule} from '@angular/core';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
|
||||
import {InventoryComponent} from './inventory.component';
|
||||
|
||||
const routes: Routes = [{
|
||||
path: '',
|
||||
component: InventoryComponent
|
||||
}, {
|
||||
path: 'materialtype',
|
||||
loadChildren: () => import('./modules/materialtype/materialtype.module').then(m => m.MaterialtypeModule)
|
||||
}];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class InventoryRoutingModule {
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
<cre-nav [links]="navLinks"></cre-nav>
|
||||
test
|
|
@ -0,0 +1,20 @@
|
|||
import {Component, OnInit} from '@angular/core';
|
||||
import {NavLink} from "../shared/components/nav/nav.component";
|
||||
|
||||
@Component({
|
||||
selector: 'cre-inventory',
|
||||
templateUrl: './inventory.component.html',
|
||||
styleUrls: ['./inventory.component.sass']
|
||||
})
|
||||
export class InventoryComponent implements OnInit {
|
||||
navLinks: NavLink[] = [
|
||||
{route: 'materialtype', title: 'Types de produit', enabled: true}
|
||||
]
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { InventoryRoutingModule } from './inventory-routing.module';
|
||||
import { InventoryComponent } from './inventory.component';
|
||||
import {SharedModule} from "../shared/shared.module";
|
||||
import { MaterialtypeModule } from './modules/materialtype/materialtype.module';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [InventoryComponent],
|
||||
imports: [
|
||||
CommonModule,
|
||||
InventoryRoutingModule,
|
||||
SharedModule,
|
||||
MaterialtypeModule
|
||||
]
|
||||
})
|
||||
export class InventoryModule { }
|
|
@ -0,0 +1,11 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
|
||||
|
||||
const routes: Routes = [];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class MaterialtypeRoutingModule { }
|
|
@ -0,0 +1,15 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { MaterialtypeRoutingModule } from './materialtype-routing.module';
|
||||
import { ListComponent } from './pages/list/list.component';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [ListComponent],
|
||||
imports: [
|
||||
CommonModule,
|
||||
MaterialtypeRoutingModule
|
||||
]
|
||||
})
|
||||
export class MaterialtypeModule { }
|
|
@ -14,7 +14,7 @@ import {takeUntil} from "rxjs/operators";
|
|||
export class HeaderComponent implements OnInit, OnDestroy {
|
||||
links: HeaderLink[] = [
|
||||
// {route: 'color', title: 'Couleurs', enabled: true},
|
||||
// {route: 'inventory', title: 'Inventaire', enabled: true},
|
||||
{route: 'inventory', title: 'Inventaire', enabled: true},
|
||||
new HeaderLink('employee', 'Employés', EmployeePermission.VIEW_EMPLOYEE),
|
||||
new HeaderLink('group', 'Groupes', EmployeePermission.VIEW_EMPLOYEE_GROUP),
|
||||
{route: 'account/login', title: 'Connexion', enabled: true},
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<nav mat-tab-nav-bar backgroundColor="primary">
|
||||
<ng-container *ngFor="let link of links">
|
||||
<a
|
||||
*ngIf="link.enabled"
|
||||
mat-tab-link
|
||||
[active]="activeLink == link.route"
|
||||
(click)="activeLink = link.route">
|
||||
{{ link.title }}
|
||||
</a>
|
||||
</ng-container>
|
||||
</nav>
|
|
@ -0,0 +1,11 @@
|
|||
@import '../../../../../custom-theme'
|
||||
|
||||
nav
|
||||
position: relative
|
||||
z-index: 99
|
||||
padding-bottom: 1px
|
||||
|
||||
a
|
||||
opacity: 1
|
||||
font-size: 1.1em
|
||||
color: white
|
|
@ -0,0 +1,72 @@
|
|||
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Employee, EmployeePermission} from "../../model/employee";
|
||||
import {AccountService} from "../../../accounts/services/account.service";
|
||||
import {Router} from "@angular/router";
|
||||
import {takeUntil} from "rxjs/operators";
|
||||
import {AppState} from "../../app-state";
|
||||
import {Subject} from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'cre-nav',
|
||||
templateUrl: './nav.component.html',
|
||||
styleUrls: ['./nav.component.sass']
|
||||
})
|
||||
export class NavComponent implements OnInit, OnDestroy {
|
||||
private _destroy$ = new Subject<boolean>()
|
||||
|
||||
@Input() links: NavLink [] = []
|
||||
|
||||
// links: NavLink[] = [
|
||||
// {route: 'materialtype', title: 'Types de produit', enabled: true}
|
||||
// ]
|
||||
_activeLink: string | null;
|
||||
|
||||
constructor(
|
||||
private accountService: AccountService,
|
||||
private router: Router,
|
||||
private appState: AppState
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.updateEnabledLinks(this.appState.authenticatedEmployee)
|
||||
|
||||
this.appState.authenticatedUser$
|
||||
.pipe(takeUntil(this._destroy$))
|
||||
.subscribe({
|
||||
next: authentication => this.updateEnabledLinks(authentication.authenticatedUser)
|
||||
})
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this._destroy$.next(true)
|
||||
this._destroy$.complete()
|
||||
}
|
||||
|
||||
set activeLink(link: string) {
|
||||
this._activeLink = link
|
||||
this.router.navigate([link])
|
||||
}
|
||||
|
||||
get activeLink() {
|
||||
return this._activeLink
|
||||
}
|
||||
|
||||
private updateEnabledLinks(employee: Employee) {
|
||||
this.links.forEach(l => {
|
||||
if (l.requiredPermission) {
|
||||
l.enabled = employee && employee.permissions.indexOf(l.requiredPermission) >= 0;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class NavLink {
|
||||
constructor(
|
||||
public route: string,
|
||||
public title: string,
|
||||
public requiredPermission?: EmployeePermission,
|
||||
public enabled = false
|
||||
) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
export class MaterialType {
|
||||
constructor(
|
||||
public id: number,
|
||||
public name: string,
|
||||
public prefix: string,
|
||||
public usePercentages: boolean
|
||||
) {
|
||||
}
|
||||
}
|
|
@ -18,28 +18,30 @@ import {ConfirmBoxComponent} from './components/confirm-box/confirm-box.componen
|
|||
import {PermissionsListComponent} from './components/permissions-list/permissions-list.component';
|
||||
import {MatChipsModule} from "@angular/material/chips";
|
||||
import {PermissionsFieldComponent} from "./components/permissions-field/permissions-field.component";
|
||||
import { NavComponent } from './components/nav/nav.component';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [HeaderComponent, EmployeeInfoComponent, LabeledIconComponent, ConfirmBoxComponent, PermissionsListComponent, PermissionsFieldComponent],
|
||||
exports: [
|
||||
CommonModule,
|
||||
HttpClientModule,
|
||||
HeaderComponent,
|
||||
MatCardModule,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatIconModule,
|
||||
MatTableModule,
|
||||
MatCheckboxModule,
|
||||
MatListModule,
|
||||
ReactiveFormsModule,
|
||||
LabeledIconComponent,
|
||||
ConfirmBoxComponent,
|
||||
PermissionsListComponent,
|
||||
PermissionsFieldComponent
|
||||
],
|
||||
declarations: [HeaderComponent, EmployeeInfoComponent, LabeledIconComponent, ConfirmBoxComponent, PermissionsListComponent, PermissionsFieldComponent, NavComponent],
|
||||
exports: [
|
||||
CommonModule,
|
||||
HttpClientModule,
|
||||
HeaderComponent,
|
||||
MatCardModule,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatIconModule,
|
||||
MatTableModule,
|
||||
MatCheckboxModule,
|
||||
MatListModule,
|
||||
ReactiveFormsModule,
|
||||
LabeledIconComponent,
|
||||
ConfirmBoxComponent,
|
||||
PermissionsListComponent,
|
||||
PermissionsFieldComponent,
|
||||
NavComponent
|
||||
],
|
||||
imports: [
|
||||
MatTabsModule,
|
||||
MatIconModule,
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.config;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.config.properties.MaterialTypeProperties;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.MaterialService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.MaterialTypeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialTypeJavaService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
@Configuration
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class InitialDataLoader implements ApplicationListener<ApplicationReadyEvent> {
|
||||
private final MaterialTypeService materialTypeService;
|
||||
private final MaterialTypeProperties materialTypeProperties;
|
||||
|
||||
@Autowired
|
||||
public InitialDataLoader(MaterialTypeService materialTypeService, MaterialTypeProperties materialTypeProperties) {
|
||||
this.materialTypeService = materialTypeService;
|
||||
this.materialTypeProperties = materialTypeProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
materialTypeService.saveSystemTypes(materialTypeProperties.getSystemTypes());
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.configuration;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.config;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Bean;
|
|
@ -1,4 +1,4 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.context.MessageSource;
|
|
@ -1,11 +1,10 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.configuration;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.config;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.ColorRecipesExplorerApplication;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.Preferences;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.config.CREProperties;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.config.MaterialTypeProperties;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.PasswordService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.files.FilesService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.config.properties.CREProperties;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.config.properties.MaterialTypeProperties;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.PasswordService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.files.FilesService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -1,4 +1,4 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model.config;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.config.properties;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
|
@ -1,43 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.configuration;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.config.MaterialTypeProperties;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
@Configuration
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class InitialDataLoader implements ApplicationListener<ApplicationReadyEvent> {
|
||||
|
||||
private MaterialTypeService materialTypeService;
|
||||
private MaterialTypeProperties materialTypeProperties;
|
||||
|
||||
@Autowired
|
||||
public InitialDataLoader(MaterialTypeService materialTypeService, MaterialTypeProperties materialTypeProperties) {
|
||||
this.materialTypeService = materialTypeService;
|
||||
this.materialTypeProperties = materialTypeProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
for (MaterialType materialType : materialTypeProperties.getDefaults()) {
|
||||
if (!materialTypeService.existsByName(materialType.getName())) {
|
||||
materialTypeService.save(materialType);
|
||||
} else {
|
||||
MaterialType found = materialTypeService.getByName(materialType.getName());
|
||||
|
||||
found.setPrefix(materialType.getPrefix());
|
||||
found.setUsePercentages(materialType.isUsePercentages());
|
||||
|
||||
materialTypeService.update(found);
|
||||
}
|
||||
|
||||
materialTypeService.addDefault(materialType);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.exception.model
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.RestException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.web.bind.annotation.ResponseStatus
|
||||
|
||||
class EntityNotFoundException(modelType: Class<out IModel>, val identifierType: IdentifierType, val identifierName: String, val requestedId: Any) : ModelException(modelType) {
|
||||
constructor(modelType: Class<out IModel>, identifierType: IdentifierType, requestedId: Any) : this(modelType, identifierType, identifierType.name, requestedId)
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
class EntityNotFoundRestException(val value: Any) : RestException(HttpStatus.NOT_FOUND) {
|
||||
override val exceptionMessage: String = "An entity could not be found with the given identifier"
|
||||
|
||||
override fun buildBody(): RestExceptionBody = object : RestExceptionBody() {
|
||||
val id = value
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.io.file;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.Preferences;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Deprecated(since = "1.3.0")
|
||||
public class FileHandler {
|
||||
|
||||
protected String name;
|
||||
protected Logger logger = Preferences.logger;
|
||||
|
||||
private FileContext context;
|
||||
private FileExtension extension;
|
||||
private File file;
|
||||
|
||||
public FileHandler(String name, FileContext context, FileExtension extension) {
|
||||
this.context = context;
|
||||
this.extension = extension;
|
||||
|
||||
setName(name);
|
||||
file = getFile();
|
||||
}
|
||||
|
||||
public boolean createFile() {
|
||||
File parent = file.getParentFile();
|
||||
|
||||
if (!isValid()) {
|
||||
if ((!parent.exists() || !parent.isDirectory()) && !parent.mkdirs()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
logger.info("Création du fichier " + file.getAbsolutePath());
|
||||
return file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
logger.error("Erreur à la création d'un fichier", e);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
logger.warn("Tentative de création du fichier existant " + file.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] readFile() {
|
||||
if (isValid()) {
|
||||
try {
|
||||
return Files.readAllBytes(getPath());
|
||||
} catch (IOException e) {
|
||||
logger.error("Erreur lors de la lecture d'un fichier", e);
|
||||
}
|
||||
}
|
||||
|
||||
logger.warn("Tentative de lecture du fichier invalide " + file.getAbsolutePath());
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean deleteFile() {
|
||||
if (isValid()) {
|
||||
logger.info("Suppression du fichier " + file.getAbsolutePath());
|
||||
return file.delete();
|
||||
}
|
||||
|
||||
logger.warn("Tentative de suppression du fichier invalide " + file.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return file.exists() && file.isFile();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
|
||||
file = getFile();
|
||||
}
|
||||
|
||||
public FileContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public Path getPath() {
|
||||
return Paths.get(String.format("%s/%s/%s%s", Preferences.uploadDirectory, context.getPath(), name, extension.getExtension()));
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return getPath().toFile();
|
||||
}
|
||||
|
||||
public enum FileContext {
|
||||
IMAGE("images"),
|
||||
SIMDUT("simdut"),
|
||||
PDF("pdf"),
|
||||
OTHERS("");
|
||||
|
||||
private String path;
|
||||
|
||||
FileContext(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
public enum FileExtension {
|
||||
JPEG("jpeg"),
|
||||
PDF("pdf"),
|
||||
TEXT("txt"),
|
||||
DATABASE("db"),
|
||||
MARKDOWN("md");
|
||||
|
||||
private String extension;
|
||||
|
||||
FileExtension(String extension) {
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
public String getExtension() {
|
||||
return "." + extension;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.io.file;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.Preferences;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Deprecated(since = "1.3.0")
|
||||
public class ImageHandler extends FileHandler {
|
||||
|
||||
public static final String IMAGES_LOCATION = Preferences.uploadDirectory + "/images";
|
||||
|
||||
private Recipe recipe;
|
||||
private int index = 0;
|
||||
private RecipeService recipeService;
|
||||
|
||||
public ImageHandler(Recipe recipe, RecipeService recipeService) {
|
||||
super(String.format("%s_%s", recipe.getId(), recipe.getName()), FileContext.IMAGE, FileExtension.JPEG);
|
||||
|
||||
this.recipe = recipe;
|
||||
this.recipeService = recipeService;
|
||||
}
|
||||
|
||||
public ImageHandler(String name, RecipeService recipeService) {
|
||||
super(name.replace(".jpeg", ""), FileContext.IMAGE, FileExtension.JPEG);
|
||||
|
||||
this.recipeService = recipeService;
|
||||
|
||||
String[] nameParts = name.split("-");
|
||||
index = Integer.parseInt(nameParts[1].replace(".jpeg", ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createFile() {
|
||||
if (recipe != null) {
|
||||
List<String> existingImages = recipeService.getImageFiles(recipe);
|
||||
|
||||
if (existingImages != null) {
|
||||
List<Integer> existingImagesIndexes = existingImages.stream().map(n -> Integer.parseInt(n.replace(name + "-", "").replace(".jpeg", ""))).collect(Collectors.toList());
|
||||
|
||||
while (existingImagesIndexes.contains(index)) {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
setName(String.format("%s-%s", getName(), index));
|
||||
return super.createFile();
|
||||
}
|
||||
|
||||
logger.warn("Tentative de créer une image sans recette");
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,179 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import org.hibernate.annotations.Fetch
|
||||
import org.hibernate.annotations.FetchMode
|
||||
import org.springframework.security.core.GrantedAuthority
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.*
|
||||
import javax.validation.constraints.NotBlank
|
||||
import javax.validation.constraints.NotNull
|
||||
import javax.validation.constraints.Size
|
||||
import kotlin.jvm.Transient
|
||||
|
||||
|
||||
private const val EMPLOYEE_ID_NULL_MESSAGE = "Un numéro d'employé est requis"
|
||||
private const val EMPLOYEE_LAST_NAME_EMPTY_MESSAGE = "Un nom est requis"
|
||||
private const val EMPLOYEE_FIRST_NAME_EMPTY_MESSAGE = "Un prénom est requis"
|
||||
private const val EMPLOYEE_PASSWORD_EMPTY_MESSAGE = "Un mot de passe est requis"
|
||||
private const val EMPLOYEE_PASSWORD_TOO_SHORT_MESSAGE = "Le mot de passe doit contenir au moins 8 caractères"
|
||||
|
||||
@Entity
|
||||
data class Employee(
|
||||
@Id
|
||||
@field:NotNull(message = EMPLOYEE_ID_NULL_MESSAGE)
|
||||
override val id: Long,
|
||||
|
||||
val firstName: String = "",
|
||||
|
||||
val lastName: String = "",
|
||||
|
||||
@JsonIgnore
|
||||
val password: String = "",
|
||||
|
||||
@JsonIgnore
|
||||
val isDefaultGroupUser: Boolean = false,
|
||||
|
||||
@JsonIgnore
|
||||
val isSystemUser: Boolean = false,
|
||||
|
||||
@field:ManyToOne
|
||||
@Fetch(FetchMode.SELECT)
|
||||
var group: EmployeeGroup? = null,
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@Fetch(FetchMode.SUBSELECT)
|
||||
@get:JsonIgnore
|
||||
val permissions: MutableList<EmployeePermission> = mutableListOf(),
|
||||
|
||||
val lastLoginTime: LocalDateTime? = null
|
||||
) : IModel {
|
||||
@JsonProperty("permissions")
|
||||
fun getFlattenedPermissions(): Iterable<EmployeePermission> = getPermissions()
|
||||
}
|
||||
|
||||
/** DTO for creating employees. Allow a [password] a [groupId]. */
|
||||
data class EmployeeDto(
|
||||
@field:NotNull(message = EMPLOYEE_ID_NULL_MESSAGE)
|
||||
val id: Long,
|
||||
|
||||
@field:NotBlank(message = EMPLOYEE_FIRST_NAME_EMPTY_MESSAGE)
|
||||
val firstName: String,
|
||||
|
||||
@field:NotBlank(message = EMPLOYEE_LAST_NAME_EMPTY_MESSAGE)
|
||||
val lastName: String,
|
||||
|
||||
@field:NotBlank(message = EMPLOYEE_PASSWORD_EMPTY_MESSAGE)
|
||||
@field:Size(min = 8, message = EMPLOYEE_PASSWORD_TOO_SHORT_MESSAGE)
|
||||
val password: String,
|
||||
|
||||
@field:ManyToOne
|
||||
@Fetch(FetchMode.SELECT)
|
||||
var groupId: Long? = null,
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
val permissions: MutableList<EmployeePermission> = mutableListOf()
|
||||
)
|
||||
|
||||
private const val GROUP_NAME_NULL_MESSAGE = "Un nom est requis"
|
||||
private const val GROUP_PERMISSIONS_EMPTY_MESSAGE = "Au moins une permission est requise"
|
||||
|
||||
@Entity
|
||||
data class EmployeeGroup(
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
override val id: Long? = null,
|
||||
|
||||
@field:NotBlank(message = GROUP_NAME_NULL_MESSAGE)
|
||||
@field:Size(min = 3)
|
||||
@Column(unique = true)
|
||||
val name: String = "",
|
||||
|
||||
@field:Size(min = 1, message = GROUP_PERMISSIONS_EMPTY_MESSAGE)
|
||||
@Enumerated(EnumType.STRING)
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
val permissions: MutableList<EmployeePermission> = mutableListOf(),
|
||||
|
||||
@OneToMany
|
||||
@JsonIgnore
|
||||
val employees: MutableList<Employee> = mutableListOf()
|
||||
) : IModel {
|
||||
fun getEmployeeCount() = employees.size
|
||||
}
|
||||
|
||||
|
||||
data class EmployeeLoginRequest(val id: Long, val password: String)
|
||||
|
||||
|
||||
enum class EmployeePermission(val impliedPermissions: List<EmployeePermission> = listOf()) {
|
||||
// View
|
||||
VIEW_EMPLOYEE,
|
||||
VIEW_EMPLOYEE_GROUP,
|
||||
VIEW(listOf(
|
||||
|
||||
)),
|
||||
|
||||
// Edit
|
||||
EDIT_EMPLOYEE(listOf(VIEW_EMPLOYEE)),
|
||||
EDIT_EMPLOYEE_PASSWORD(listOf(EDIT_EMPLOYEE)),
|
||||
EDIT_EMPLOYEE_GROUP(listOf(VIEW_EMPLOYEE_GROUP)),
|
||||
EDIT(listOf(
|
||||
VIEW
|
||||
)),
|
||||
|
||||
// Remove
|
||||
REMOVE_EMPLOYEE(listOf(EDIT_EMPLOYEE)),
|
||||
REMOVE_EMPLOYEE_GROUP(listOf(EDIT_EMPLOYEE_GROUP)),
|
||||
REMOVE(listOf(
|
||||
EDIT
|
||||
)),
|
||||
|
||||
// Others
|
||||
SET_BROWSER_DEFAULT_GROUP(listOf(
|
||||
VIEW_EMPLOYEE_GROUP
|
||||
)),
|
||||
|
||||
ADMIN(listOf(
|
||||
REMOVE,
|
||||
SET_BROWSER_DEFAULT_GROUP,
|
||||
|
||||
// Admin only permissions
|
||||
REMOVE_EMPLOYEE,
|
||||
EDIT_EMPLOYEE_PASSWORD,
|
||||
REMOVE_EMPLOYEE_GROUP,
|
||||
));
|
||||
|
||||
operator fun contains(permission: EmployeePermission): Boolean {
|
||||
return permission == this || impliedPermissions.any { permission in it }
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets [GrantedAuthority]s of the given [Employee]. */
|
||||
fun Employee.getAuthorities(): MutableCollection<GrantedAuthority> {
|
||||
return getPermissions().map { it.toAuthority() }.toMutableSet()
|
||||
}
|
||||
|
||||
/** Gets [EmployeePermission]s of the given [Employee]. */
|
||||
fun Employee.getPermissions(): Iterable<EmployeePermission> {
|
||||
val grantedPermissions: MutableSet<EmployeePermission> = mutableSetOf()
|
||||
if (group != null) grantedPermissions.addAll(group!!.permissions.flatMap { it.flat() })
|
||||
grantedPermissions.addAll(permissions.flatMap { it.flat() })
|
||||
return grantedPermissions
|
||||
}
|
||||
|
||||
private fun EmployeePermission.flat(): Iterable<EmployeePermission> {
|
||||
return mutableSetOf(this).apply {
|
||||
impliedPermissions.forEach {
|
||||
addAll(it.flat())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Converts the given [EmployeePermission] to a [GrantedAuthority]. */
|
||||
private fun EmployeePermission.toAuthority(): GrantedAuthority {
|
||||
return SimpleGrantedAuthority(name)
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model
|
||||
|
||||
interface IModel {
|
||||
val id: Long?
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model
|
||||
|
||||
import org.springframework.lang.Nullable
|
||||
import javax.persistence.*
|
||||
import javax.validation.constraints.NotEmpty
|
||||
import javax.validation.constraints.NotNull
|
||||
|
||||
@Entity
|
||||
data class Material(
|
||||
@Nullable @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) override val id: Long?,
|
||||
@NotNull @NotEmpty @Column(unique = true) var name: String?,
|
||||
@NotNull var inventoryQuantity: Float,
|
||||
@NotNull val isMixType: Boolean,
|
||||
@NotNull @ManyToOne var materialType: MaterialType?
|
||||
) : IModel {
|
||||
constructor(name: String, inventoryQuantity: Float, isMixType: Boolean, materialType: MaterialType) : this(null, name, inventoryQuantity, isMixType, materialType)
|
||||
constructor() : this(-1L, "", 0f, false, null)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is Material && name == other.name
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return name.hashCode()
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model;
|
||||
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MaterialType implements IModel {
|
||||
|
||||
public static final String IDENTIFIER_PREFIX_NAME = "prefix";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Long id;
|
||||
|
||||
@NonNull
|
||||
@NotNull
|
||||
@Column(unique = true)
|
||||
private String name;
|
||||
|
||||
@NonNull
|
||||
@NotNull
|
||||
@Column(unique = true)
|
||||
private String prefix;
|
||||
|
||||
@NonNull
|
||||
@NotNull
|
||||
@ColumnDefault("false")
|
||||
private boolean usePercentages;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MaterialType that = (MaterialType) o;
|
||||
return name.equals(that.name) &&
|
||||
prefix.equals(that.prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, prefix);
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model.config;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "entities.material-types")
|
||||
@Getter
|
||||
@Setter
|
||||
public class MaterialTypeProperties {
|
||||
|
||||
private List<MaterialType> defaults;
|
||||
|
||||
private String baseName;
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services
|
||||
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundRestException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
|
||||
/** A service implementing the basics CRUD operations. */
|
||||
interface IGenericService<E> {
|
||||
/** Gets all entities. */
|
||||
fun getAll(): Collection<E>
|
||||
|
||||
/** Saves a given [entity]. */
|
||||
fun save(entity: E): E
|
||||
|
||||
/** Saves all given [entities]. */
|
||||
fun saveAll(entities: Iterable<E>): Collection<E>
|
||||
|
||||
/** Updates a given [entity]. */
|
||||
fun update(entity: E): E
|
||||
|
||||
/** Deletes a given [entity]. */
|
||||
fun delete(entity: E)
|
||||
|
||||
/** Deletes all give [entities]. */
|
||||
fun deleteAll(entities: Iterable<E>)
|
||||
}
|
||||
|
||||
/** A service for entities implementing the [IModel] interface. This service implements CRUD operations for [Long] identifiers. */
|
||||
interface IGenericModelService<E : IModel> : IGenericService<E> {
|
||||
/** Checks if an entity with the given [id] exists. */
|
||||
fun existsById(id: Long): Boolean
|
||||
|
||||
/** Gets the entity with the given [id]. */
|
||||
fun getById(id: Long): E
|
||||
|
||||
/** Deletes the entity with the given [id]. */
|
||||
fun deleteById(id: Long)
|
||||
}
|
||||
|
||||
abstract class AbstractService<E, R : JpaRepository<E, *>>(val repository: R, val type: Class<out IModel>) : IGenericService<E> {
|
||||
override fun getAll(): Collection<E> = repository.findAll()
|
||||
|
||||
override fun save(entity: E): E = repository.save(entity)
|
||||
|
||||
override fun saveAll(entities: Iterable<E>): Collection<E> = entities.map(this::save)
|
||||
|
||||
override fun update(entity: E): E = repository.save(entity)
|
||||
|
||||
override fun delete(entity: E) = repository.delete(entity)
|
||||
|
||||
override fun deleteAll(entities: Iterable<E>) = entities.forEach(this::delete)
|
||||
}
|
||||
|
||||
abstract class AbstractModelService<E : IModel, R : JpaRepository<E, Long>>(repository: R, type: Class<out IModel>) : AbstractService<E, R>(repository, type), IGenericModelService<E> {
|
||||
override fun existsById(id: Long): Boolean = repository.existsById(id)
|
||||
|
||||
override fun getById(id: Long): E = repository.findByIdOrNull(id)
|
||||
?: throw EntityNotFoundException(type, ModelException.IdentifierType.ID, id)
|
||||
|
||||
override fun save(entity: E): E {
|
||||
with(entity.id) {
|
||||
if (this != null && existsById(this))
|
||||
throw EntityNotFoundRestException(this)
|
||||
}
|
||||
|
||||
return super.save(entity)
|
||||
}
|
||||
|
||||
override fun deleteById(id: Long) = delete(getById(id))
|
||||
}
|
||||
|
||||
/** Transforms the given object to JSON. **/
|
||||
fun Any.asJson(): String {
|
||||
return jacksonObjectMapper().writeValueAsString(this)
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.files.SimdutService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MaterialRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class MaterialService extends AbstractJavaService<Material, MaterialRepository> {
|
||||
|
||||
private MixQuantityService mixQuantityService;
|
||||
private SimdutService simdutService;
|
||||
|
||||
public MaterialService() {
|
||||
super(Material.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMaterialDao(MaterialRepository materialRepository) {
|
||||
this.dao = materialRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMixQuantityService(MixQuantityService mixQuantityService) {
|
||||
this.mixQuantityService = mixQuantityService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setSimdutService(SimdutService simdutService) {
|
||||
this.simdutService = simdutService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un produit correspondant à un nom existe.
|
||||
*
|
||||
* @param name Le nom du produit
|
||||
* @return Si un produit correspondant au nom existe
|
||||
*/
|
||||
public boolean existsByName(String name) {
|
||||
return dao.existsByName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si des produits sont d'un type de produit
|
||||
*
|
||||
* @param materialType Le type de produit
|
||||
* @return Si des produits sont du type de produit
|
||||
*/
|
||||
public boolean existsByMaterialType(MaterialType materialType) {
|
||||
return dao.existsByMaterialType(materialType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un produit est lié à un ou plusieurs mélanges.
|
||||
*
|
||||
* @param material Le produit à vérifier.
|
||||
* @return Si le produit est lié à d'autres mélanges.
|
||||
*/
|
||||
public boolean isLinkedToMixes(Material material) {
|
||||
return mixQuantityService.existsByMaterial(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère tous les produits qui ne sont pas des types de mélange.
|
||||
*
|
||||
* @return Tous les produits qui ne sont pas des types de mélange
|
||||
*/
|
||||
public List<Material> getAllNotMixType() {
|
||||
return getAll()
|
||||
.stream()
|
||||
.filter(m -> !m.isMixType())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le produit correspondant à un nom.
|
||||
*
|
||||
* @param name Le nom du produit à récupérer
|
||||
* @return Le produit correspondant au nom
|
||||
*/
|
||||
public Material getByName(String name) {
|
||||
Optional<Material> found = dao.findByName(name);
|
||||
if (found.isEmpty()) throw new EntityNotFoundException(type, ModelException.IdentifierType.NAME, name);
|
||||
|
||||
return found.get();
|
||||
}
|
||||
|
||||
public Material save(@NotNull Material material, MultipartFile file) {
|
||||
if (existsByName(material.getName()))
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.NAME, material.getName());
|
||||
|
||||
Material saved = save(material);
|
||||
|
||||
if (!file.isEmpty()) simdutService.write(saved, file);
|
||||
|
||||
return saved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material update(Material material) {
|
||||
Optional<Material> materialByName = dao.findByName(material.getName());
|
||||
if (materialByName.isPresent() && material.getId() != materialByName.get().getId())
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.NAME, material.getName());
|
||||
|
||||
return super.update(material);
|
||||
}
|
||||
|
||||
public Material update(Material material, MultipartFile simdut) {
|
||||
simdutService.update(simdut, material);
|
||||
|
||||
return update(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Material material) {
|
||||
simdutService.delete(material);
|
||||
|
||||
super.delete(material);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
public void deleteIfNotLinked(Material material) {
|
||||
if (!isLinkedToMixes(material)) {
|
||||
delete(material);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.utils;
|
||||
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
public class FileUtils {
|
||||
|
||||
public static String readClasspathFile(ResourceLoader loader, String path) {
|
||||
try (InputStream stream = loader.getResource(path).getInputStream()) {
|
||||
byte[] data = FileCopyUtils.copyToByteArray(stream);
|
||||
return new String(data, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.dao;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface MaterialRepository extends JpaRepository<Material, Long> {
|
||||
|
||||
boolean existsByName(String name);
|
||||
|
||||
boolean existsByMaterialType(MaterialType materialType);
|
||||
|
||||
Optional<Material> findByName(String name);
|
||||
|
||||
List<Material> findAllByMaterialType(MaterialType materialType);
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.dao;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface MaterialTypeRepository extends JpaRepository<MaterialType, Long> {
|
||||
|
||||
boolean existsByName(String name);
|
||||
|
||||
boolean existsByPrefix(String prefix);
|
||||
|
||||
Optional<MaterialType> findByPrefix(String prefix);
|
||||
|
||||
Optional<MaterialType> findByName(String name);
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.exception;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.exception;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
|
@ -1,6 +1,6 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.exception;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.exception;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MaterialTypeEditorDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.dto.MaterialTypeEditorDto;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
|
@ -1,7 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.exception
|
||||
package dev.fyloz.trial.colorrecipesexplorer.exception
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.*
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.*
|
||||
import org.springframework.context.annotation.Profile
|
||||
import org.springframework.http.HttpHeaders
|
||||
import org.springframework.http.HttpStatus
|
||||
|
@ -39,7 +39,7 @@ class RestResponseEntityExceptionHandler : ResponseEntityExceptionHandler() {
|
|||
val errors = hashMapOf<String, String>()
|
||||
ex.bindingResult.allErrors.forEach {
|
||||
val fieldName = (it as FieldError).field
|
||||
val errorMessage = it.defaultMessage
|
||||
val errorMessage = it.defaultMessage!!
|
||||
errors[fieldName] = errorMessage
|
||||
}
|
||||
return ResponseEntity(errors, headers, status)
|
|
@ -1,6 +1,6 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.exception;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.exception;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
|
||||
public class SimdutException extends RuntimeException {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.exception;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.exception;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
|
@ -1,6 +1,6 @@
|
|||
//package dev.fyloz.trial.colorrecipesexplorer.core.exception.model;
|
||||
//package dev.fyloz.trial.colorrecipesexplorer.exception.model;
|
||||
//
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.model.IModel;
|
||||
//import lombok.Getter;
|
||||
//import lombok.NonNull;
|
||||
//import org.springframework.http.HttpStatus;
|
|
@ -1,12 +1,12 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.exception.model
|
||||
package dev.fyloz.trial.colorrecipesexplorer.exception.model
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.RestException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.RestException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Model
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.web.bind.annotation.ResponseStatus
|
||||
|
||||
class EntityAlreadyExistsException(modelType: Class<out IModel>, val identifierType: IdentifierType, val identifierName: String?, val requestedId: Any) : ModelException(modelType) {
|
||||
constructor(modelType: Class<out IModel>, identifierType: IdentifierType, requestedId: Any) : this(modelType, identifierType, identifierType.name, requestedId)
|
||||
class EntityAlreadyExistsException(modelType: Class<out Model>, val identifierType: IdentifierType, val identifierName: String?, val requestedId: Any) : ModelException(modelType) {
|
||||
constructor(modelType: Class<out Model>, identifierType: IdentifierType, requestedId: Any) : this(modelType, identifierType, identifierType.name, requestedId)
|
||||
constructor(exception: EntityAlreadyExistsException) : this(exception.type, exception.identifierType, exception.identifierName, exception.requestedId)
|
||||
}
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.exception.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.exception.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Model;
|
||||
|
||||
/**
|
||||
* Représente une exception qui sera lancée lorsqu'un objet du modèle qui est lié à un autre entité doit être supprimé
|
||||
*/
|
||||
public class EntityLinkedException extends ModelException {
|
||||
|
||||
public EntityLinkedException(Class<? extends IModel> type) {
|
||||
public EntityLinkedException(Class<? extends Model> type) {
|
||||
super(type);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
//package dev.fyloz.trial.colorrecipesexplorer.core.exception.model;
|
||||
//package dev.fyloz.trial.colorrecipesexplorer.exception.model;
|
||||
//
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.model.IModel;
|
||||
//import lombok.Getter;
|
||||
//
|
||||
///**
|
|
@ -0,0 +1,19 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.exception.model
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.RestException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Model
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.web.bind.annotation.ResponseStatus
|
||||
|
||||
class EntityNotFoundException(modelType: Class<out Model>, val identifierType: IdentifierType, val identifierName: String, val requestedId: Any) : ModelException(modelType) {
|
||||
constructor(modelType: Class<out Model>, identifierType: IdentifierType, requestedId: Any) : this(modelType, identifierType, identifierType.name, requestedId)
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
class EntityNotFoundRestException(val value: Any) : RestException(HttpStatus.NOT_FOUND) {
|
||||
override val exceptionMessage: String = "An entity could not be found with the given identifier"
|
||||
|
||||
override fun buildBody(): RestExceptionBody = object : RestExceptionBody() {
|
||||
val id = value
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.exception.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.exception.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Model;
|
||||
|
||||
/**
|
||||
* Représente une exception qui sera déclenchée lors des opérations sur le modèle.
|
||||
|
@ -10,13 +10,13 @@ public class ModelException extends RuntimeException {
|
|||
/**
|
||||
* Le type de modèle qui est sujet à l'exception
|
||||
*/
|
||||
protected Class<? extends IModel> type;
|
||||
protected Class<? extends Model> type;
|
||||
|
||||
public ModelException(Class<? extends IModel> type) {
|
||||
public ModelException(Class<? extends Model> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Class<? extends IModel> getType() {
|
||||
public Class<? extends Model> getType() {
|
||||
return type;
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.exception.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.exception.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Model;
|
||||
|
||||
public class NullIdentifierException extends ModelException {
|
||||
|
||||
public NullIdentifierException(Class<? extends IModel> type) {
|
||||
public NullIdentifierException(Class<? extends Model> type) {
|
||||
super(type);
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model;
|
||||
|
||||
import lombok.*;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
|
@ -13,7 +13,7 @@ import java.util.Objects;
|
|||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Company implements IModel {
|
||||
public class Company implements Model {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
|
@ -1,6 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model;
|
||||
|
||||
import lombok.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
@ -11,7 +12,8 @@ import java.util.Objects;
|
|||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Mix implements IModel {
|
||||
@AllArgsConstructor
|
||||
public class Mix implements Model {
|
||||
|
||||
public static final String IDENTIFIER_MIX_TYPE_NAME = "mixType";
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
@ -11,7 +12,8 @@ import java.util.Objects;
|
|||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MixQuantity implements IModel {
|
||||
@AllArgsConstructor
|
||||
public class MixQuantity implements Model {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
|
@ -1,6 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model;
|
||||
|
||||
import lombok.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
@ -11,7 +12,7 @@ import java.util.Objects;
|
|||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MixType implements IModel {
|
||||
public class MixType implements Model {
|
||||
|
||||
public static final String IDENTIFIER_MATERIAL_NAME = "material";
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.*;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
@ -13,7 +14,7 @@ import java.util.stream.Collectors;
|
|||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Recipe implements IModel {
|
||||
public class Recipe implements Model {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
|
@ -1,18 +1,19 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class RecipeStep implements IModel {
|
||||
@AllArgsConstructor
|
||||
public class RecipeStep implements Model {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
|
@ -1,3 +1,3 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model.dto
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model.dto
|
||||
|
||||
data class InventoryDto(val mixId: Long, val materialIds: List<Long>, val quantities: List<Float>)
|
|
@ -1,6 +1,6 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model.dto;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model.dto;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -28,15 +28,15 @@ public class MaterialTypeEditorDto {
|
|||
this.name = materialType.getName();
|
||||
this.oldPrefix = materialType.getPrefix();
|
||||
this.prefix = materialType.getPrefix();
|
||||
this.usePercentages = materialType.isUsePercentages();
|
||||
this.usePercentages = materialType.getUsePercentages();
|
||||
}
|
||||
|
||||
public MaterialType getMaterialType() {
|
||||
return new MaterialType(id, name, prefix, usePercentages);
|
||||
return new MaterialType(id, name, prefix, usePercentages, false);
|
||||
}
|
||||
|
||||
public MaterialType getOldMaterialType() {
|
||||
return new MaterialType(id, oldName, oldPrefix, usePercentages);
|
||||
return new MaterialType(id, oldName, oldPrefix, usePercentages, false);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model.dto;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model.dto;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model.dto;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model.dto;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
|
@ -1,4 +1,4 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.model.dto;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.dao;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.repository;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Company;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.dao;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.repository;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixQuantity;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MixQuantity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.dao;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.repository;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.dao;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.repository;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MixType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.dao;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.repository;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
|
@ -1,7 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.dao;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.repository;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.RecipeStep;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.RecipeStep;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
|
@ -0,0 +1,29 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.service;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.NamedModel;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.repository.NamedJpaRepository;
|
||||
|
||||
abstract public class AbstractJavaNamedService<E extends NamedModel, R extends NamedJpaRepository<E>> extends AbstractJavaService<E, R> {
|
||||
|
||||
public AbstractJavaNamedService(Class<E> type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
public boolean existsByName(String name) {
|
||||
return repository.existsByName(name);
|
||||
}
|
||||
|
||||
public E getByName(String name) {
|
||||
E found = repository.findByName(name);
|
||||
if (found == null) throw new EntityNotFoundException(type, ModelException.IdentifierType.NAME, name);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
public void deleteByName(String name) {
|
||||
repository.deleteByName(name);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,14 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.Preferences;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.NullIdentifierException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.config.Preferences;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.NullIdentifierException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Model;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -18,37 +19,72 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class AbstractJavaService<E extends IModel, R extends JpaRepository<E, Long>> implements IGenericJavaService<E> {
|
||||
public abstract class AbstractJavaService<E extends Model, R extends JpaRepository<E, Long>> implements IGenericJavaService<E> {
|
||||
|
||||
protected Logger logger = Preferences.logger;
|
||||
protected R dao;
|
||||
protected R repository;
|
||||
protected Class<E> type;
|
||||
|
||||
public AbstractJavaService(Class<E> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(E entity) {
|
||||
return entity != null && entity.getId() != null && existsById(entity.getId());
|
||||
public R getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsById(Long id) {
|
||||
return dao.existsById(id);
|
||||
return repository.existsById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si une entité correspondant à un identifiant existe.
|
||||
* <p>
|
||||
* Méthode pour la compatibilité avec les services Kotlin.
|
||||
*
|
||||
* @param id L'identifiant de l'entité
|
||||
* @return Si un entité correspondant à l'identifiant existe
|
||||
*/
|
||||
public boolean existsById(long id) {
|
||||
return existsById(Long.valueOf(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode utilitaire pour wrapper les entités nullables dans un Optional.
|
||||
* <p>
|
||||
* Méthode pour la compatibilité avec les repository Kotlin.
|
||||
*
|
||||
* @param entity L'entité nullable
|
||||
* @return Un optional wrapper l'entité donnée
|
||||
*/
|
||||
protected Optional<E> findOptional(@Nullable E entity) {
|
||||
return Optional.ofNullable(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getById(Long id) {
|
||||
Optional<E> found = dao.findById(id);
|
||||
Optional<E> found = repository.findById(id);
|
||||
if (found.isEmpty()) throw new EntityNotFoundException(type, EntityNotFoundException.IdentifierType.ID, id);
|
||||
|
||||
return found.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère l'entité de type T correspondant à un identifiant.
|
||||
* <p>
|
||||
* Méthode pour la compatibilité avec les services Kotlin.
|
||||
*
|
||||
* @param id L'identifiant de l'entité
|
||||
* @return L'entité correspondant à l'identifiant
|
||||
*/
|
||||
public E getById(long id) {
|
||||
return getById(Long.valueOf(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<E> getAll() {
|
||||
return dao.findAll();
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +92,7 @@ public abstract class AbstractJavaService<E extends IModel, R extends JpaReposit
|
|||
if (entity.getId() != null && existsById(entity.getId()))
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.ID, entity.getId());
|
||||
|
||||
return dao.save(entity);
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -74,12 +110,12 @@ public abstract class AbstractJavaService<E extends IModel, R extends JpaReposit
|
|||
if (!existsById(entity.getId()))
|
||||
throw new EntityNotFoundException(type, ModelException.IdentifierType.ID, entity.getId());
|
||||
|
||||
return dao.save(entity);
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(@NotNull E entity) {
|
||||
dao.delete(entity);
|
||||
repository.delete(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,31 +123,20 @@ public abstract class AbstractJavaService<E extends IModel, R extends JpaReposit
|
|||
delete(getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime une entité correspondant à l'identifiant.
|
||||
* <p>
|
||||
* Méthode pour la compatibilité avec les services Kotlin.
|
||||
*
|
||||
* @param id L'identifiant de l'entité à supprimer
|
||||
*/
|
||||
public void deleteById(long id) {
|
||||
deleteById(Long.valueOf(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Collection<E> entities) {
|
||||
dao.deleteAll(entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si une entité est valide pour la création dans la base de données.
|
||||
*
|
||||
* @param entity L'entité à vérifier.
|
||||
* @return Si l'entité est valide pour la création.
|
||||
*/
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
public boolean isValidForCreation(E entity) {
|
||||
return entity != null && !existsById(entity.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si une entité est valide pour la création dans la base de données.
|
||||
*
|
||||
* @param entity L'entité à vérifier.
|
||||
* @return Si l'entité est valide pour l'édition.
|
||||
*/
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
public boolean isValidForUpdate(@NotNull E entity) {
|
||||
return entity.getId() != null && existsById(entity.getId());
|
||||
repository.deleteAll(entities);
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,14 +1,11 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.IModel;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface IGenericJavaService<T extends IModel> {
|
||||
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
boolean exists(T entity);
|
||||
public interface IGenericJavaService<T extends Model> {
|
||||
|
||||
/**
|
||||
* Vérifie si une entité correspondant à un identifiant existe.
|
|
@ -1,4 +1,4 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -1,6 +1,6 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.files;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.files;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.Preferences;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.config.Preferences;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.stereotype.Service;
|
|
@ -1,4 +1,4 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.files;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.files;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
|
@ -1,4 +1,4 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.files;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.files;
|
||||
|
||||
import org.commonmark.node.Node;
|
||||
import org.commonmark.parser.Parser;
|
|
@ -1,8 +1,8 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.files;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.files;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.SimdutException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialJavaService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -16,7 +16,7 @@ public class SimdutService {
|
|||
private static final String SIMDUT_DIRECTORY = "simdut";
|
||||
|
||||
private FilesService filesService;
|
||||
private MaterialService materialService;
|
||||
private MaterialJavaService materialService;
|
||||
|
||||
@Autowired
|
||||
public SimdutService(FilesService filesService) {
|
||||
|
@ -25,7 +25,7 @@ public class SimdutService {
|
|||
|
||||
@Autowired
|
||||
@Lazy
|
||||
public void setMaterialService(MaterialService materialService) {
|
||||
public void setMaterialService(MaterialJavaService materialService) {
|
||||
this.materialService = materialService;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.files;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.files;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.utils.PdfBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.utils.PdfBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.stereotype.Service;
|
|
@ -1,8 +1,8 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.files;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.files;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.Preferences;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.config.Preferences;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.RecipeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.xlsx.XlsxExporter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
|
@ -1,11 +1,11 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityLinkedException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.CompanyRepository;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityLinkedException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.repository.CompanyRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -23,7 +23,7 @@ public class CompanyService extends AbstractJavaService<Company, CompanyReposito
|
|||
|
||||
@Autowired
|
||||
public void setCompanyDao(CompanyRepository companyRepository) {
|
||||
this.dao = companyRepository;
|
||||
this.repository = companyRepository;
|
||||
}
|
||||
|
||||
// Pour éviter les dépendances circulaires
|
||||
|
@ -40,7 +40,7 @@ public class CompanyService extends AbstractJavaService<Company, CompanyReposito
|
|||
* @return Si une bannière correspondant au nome existe
|
||||
*/
|
||||
public boolean existsByName(String name) {
|
||||
return dao.existsByName(name);
|
||||
return repository.existsByName(name);
|
||||
}
|
||||
|
||||
/**
|
|
@ -0,0 +1,109 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.service.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialSaveDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialUpdateDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.repository.MaterialRepository;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.AbstractJavaNamedService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.files.SimdutService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class MaterialJavaService extends AbstractJavaNamedService<Material, MaterialRepository> {
|
||||
|
||||
private MixQuantityService mixQuantityService;
|
||||
private SimdutService simdutService;
|
||||
|
||||
public MaterialJavaService() {
|
||||
super(Material.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMaterialDao(MaterialRepository materialRepository) {
|
||||
this.repository = materialRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMixQuantityService(MixQuantityService mixQuantityService) {
|
||||
this.mixQuantityService = mixQuantityService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setSimdutService(SimdutService simdutService) {
|
||||
this.simdutService = simdutService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si des produits sont d'un type de produit
|
||||
*
|
||||
* @param materialType Le type de produit
|
||||
* @return Si des produits sont du type de produit
|
||||
*/
|
||||
public boolean existsByMaterialType(MaterialType materialType) {
|
||||
return repository.existsByMaterialType(materialType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un produit est lié à un ou plusieurs mélanges.
|
||||
*
|
||||
* @param material Le produit à vérifier.
|
||||
* @return Si le produit est lié à d'autres mélanges.
|
||||
*/
|
||||
public boolean isLinkedToMixes(Material material) {
|
||||
return mixQuantityService.existsByMaterial(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère tous les produits qui ne sont pas des types de mélange.
|
||||
*
|
||||
* @return Tous les produits qui ne sont pas des types de mélange
|
||||
*/
|
||||
@NotNull
|
||||
public List<Material> getAllNotMixType() {
|
||||
return getAll()
|
||||
.stream()
|
||||
.filter(m -> !m.isMixType())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Material save(MaterialSaveDto material) {
|
||||
if (existsByName(material.getName()))
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.NAME, material.getName());
|
||||
Material saved = save(material.toMaterial());
|
||||
if (material.getSimdutFile() != null && !material.getSimdutFile().isEmpty())
|
||||
simdutService.write(saved, material.getSimdutFile());
|
||||
return saved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material update(Material material) {
|
||||
Optional<Material> materialByName = findOptional(repository.findByName(material.getName()));
|
||||
if (materialByName.isPresent() && !Objects.equals(material.getId(), materialByName.get().getId()))
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.NAME, material.getName());
|
||||
|
||||
return super.update(material);
|
||||
}
|
||||
|
||||
public Material update(MaterialUpdateDto material) {
|
||||
simdutService.update(material.getSimdutFile(), material.toMaterial());
|
||||
return update(material.toMaterial());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Material material) {
|
||||
simdutService.delete(material);
|
||||
|
||||
super.delete(material);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,15 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.CannotDeleteDefaultMaterialTypeException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.CannotEditDefaultMaterialTypeException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MaterialTypeEditorDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MaterialTypeRepository;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotDeleteDefaultMaterialTypeException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotEditDefaultMaterialTypeException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.dto.MaterialTypeEditorDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.repository.MaterialTypeRepository;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialTypeKt;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -19,23 +20,23 @@ import java.util.Optional;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class MaterialTypeService extends AbstractJavaService<MaterialType, MaterialTypeRepository> {
|
||||
public class MaterialTypeJavaService extends AbstractJavaService<MaterialType, MaterialTypeRepository> {
|
||||
|
||||
private MaterialService materialService;
|
||||
private MaterialJavaService materialService;
|
||||
|
||||
private List<MaterialType> defaultMaterialTypes = new LinkedList<>();
|
||||
|
||||
public MaterialTypeService() {
|
||||
public MaterialTypeJavaService() {
|
||||
super(MaterialType.class);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMaterialTypeDao(MaterialTypeRepository materialTypeRepository) {
|
||||
this.dao = materialTypeRepository;
|
||||
this.repository = materialTypeRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMaterialService(MaterialService materialService) {
|
||||
public void setMaterialService(MaterialJavaService materialService) {
|
||||
this.materialService = materialService;
|
||||
}
|
||||
|
||||
|
@ -69,7 +70,7 @@ public class MaterialTypeService extends AbstractJavaService<MaterialType, Mater
|
|||
* @return Si un type de produit ayant le nom existe
|
||||
*/
|
||||
public boolean existsByName(String name) {
|
||||
return dao.existsByName(name);
|
||||
return repository.existsByName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +80,7 @@ public class MaterialTypeService extends AbstractJavaService<MaterialType, Mater
|
|||
* @return Si un type de produit ayant le préfixe existe
|
||||
*/
|
||||
public boolean existsByPrefix(String prefix) {
|
||||
return dao.existsByPrefix(prefix);
|
||||
return repository.existsByPrefix(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,7 +111,7 @@ public class MaterialTypeService extends AbstractJavaService<MaterialType, Mater
|
|||
* @return Le type de produit correspondant au nom.
|
||||
*/
|
||||
public MaterialType getByName(String name) {
|
||||
Optional<MaterialType> found = dao.findByName(name);
|
||||
Optional<MaterialType> found = findOptional(repository.findByName(name));
|
||||
if (found.isEmpty())
|
||||
throw new EntityNotFoundException(type, ModelException.IdentifierType.NAME, name);
|
||||
|
||||
|
@ -122,7 +123,7 @@ public class MaterialTypeService extends AbstractJavaService<MaterialType, Mater
|
|||
if (existsByName(materialType.getName()))
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.NAME, materialType.getName());
|
||||
if (existsByPrefix(materialType.getPrefix()))
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.OTHER, MaterialType.IDENTIFIER_PREFIX_NAME, materialType.getPrefix());
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.OTHER, MaterialTypeKt.IDENTIFIER_PREFIX_NAME, materialType.getPrefix());
|
||||
|
||||
return super.save(materialType);
|
||||
}
|
||||
|
@ -137,7 +138,7 @@ public class MaterialTypeService extends AbstractJavaService<MaterialType, Mater
|
|||
if (!materialTypeDto.getOldName().equals(materialType.getName()) && existsByName(materialType.getName()))
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.NAME, materialType.getName());
|
||||
if (!materialTypeDto.getOldPrefix().equals(materialType.getPrefix()) && existsByPrefix(materialType.getPrefix()))
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.OTHER, MaterialType.IDENTIFIER_PREFIX_NAME, materialType.getPrefix());
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.OTHER, MaterialTypeKt.IDENTIFIER_PREFIX_NAME, materialType.getPrefix());
|
||||
|
||||
return super.update(materialType);
|
||||
}
|
||||
|
@ -148,25 +149,4 @@ public class MaterialTypeService extends AbstractJavaService<MaterialType, Mater
|
|||
|
||||
super.delete(materialType);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
public void deleteIfNotLinked(MaterialType materialType) {
|
||||
if (!isLinkedToMaterials(materialType)) {
|
||||
delete(materialType);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
public boolean isValidForUpdateName(MaterialType materialType) {
|
||||
MaterialType materialTypeByName = dao.findByName(materialType.getName()).get();
|
||||
|
||||
return materialType.getId().equals(materialTypeByName.getId());
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
public boolean isValidForUpdatePrefix(MaterialType materialType) {
|
||||
MaterialType materialTypeByPrefix = dao.findByPrefix(materialType.getPrefix()).get();
|
||||
|
||||
return materialType.getId().equals(materialTypeByPrefix.getId());
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixQuantity;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MixQuantityRepository;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MixQuantity;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.repository.MixQuantityRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class MixQuantityService extends AbstractJavaService<MixQuantity, MixQuan
|
|||
|
||||
@Autowired
|
||||
public void setMixQuantityDao(MixQuantityRepository mixQuantityRepository) {
|
||||
this.dao = mixQuantityRepository;
|
||||
this.repository = mixQuantityRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,6 +26,6 @@ public class MixQuantityService extends AbstractJavaService<MixQuantity, MixQuan
|
|||
* @return S'il y a un mélange qui contient le produit
|
||||
*/
|
||||
public boolean existsByMaterial(Material material) {
|
||||
return dao.existsByMaterial(material);
|
||||
return repository.existsByMaterial(material);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MixFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.utils.MixBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MixRepository;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.dto.MixFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.utils.MixBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.repository.MixRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -21,7 +21,7 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class MixService extends AbstractJavaService<Mix, MixRepository> {
|
||||
|
||||
private MaterialService materialService;
|
||||
private MaterialJavaService materialService;
|
||||
private MixQuantityService mixQuantityService;
|
||||
private MixTypeService mixTypeService;
|
||||
|
||||
|
@ -31,11 +31,11 @@ public class MixService extends AbstractJavaService<Mix, MixRepository> {
|
|||
|
||||
@Autowired
|
||||
public void setMixDao(MixRepository mixRepository) {
|
||||
this.dao = mixRepository;
|
||||
this.repository = mixRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMaterialService(MaterialService materialService) {
|
||||
public void setMaterialService(MaterialJavaService materialService) {
|
||||
this.materialService = materialService;
|
||||
}
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MixTypeRepository;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.repository.MixTypeRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -17,7 +17,7 @@ import java.util.Optional;
|
|||
@Service
|
||||
public class MixTypeService extends AbstractJavaService<MixType, MixTypeRepository> {
|
||||
|
||||
private MaterialService materialService;
|
||||
private MaterialJavaService materialService;
|
||||
|
||||
public MixTypeService() {
|
||||
super(MixType.class);
|
||||
|
@ -25,11 +25,11 @@ public class MixTypeService extends AbstractJavaService<MixType, MixTypeReposito
|
|||
|
||||
@Autowired
|
||||
public void setMixTypeDao(MixTypeRepository mixTypeRepository) {
|
||||
this.dao = mixTypeRepository;
|
||||
this.repository = mixTypeRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMaterialService(MaterialService materialService) {
|
||||
public void setMaterialService(MaterialJavaService materialService) {
|
||||
this.materialService = materialService;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class MixTypeService extends AbstractJavaService<MixType, MixTypeReposito
|
|||
* @return Si un type de mélange correspondant au nom existe
|
||||
*/
|
||||
public boolean existsByName(String name) {
|
||||
return dao.existsByName(name);
|
||||
return repository.existsByName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ public class MixTypeService extends AbstractJavaService<MixType, MixTypeReposito
|
|||
* @return Le type de mélange correspondant au nom
|
||||
*/
|
||||
public MixType getByName(String name) {
|
||||
Optional<MixType> found = dao.findByName(name);
|
||||
Optional<MixType> found = repository.findByName(name);
|
||||
if (found.isEmpty()) throw new EntityNotFoundException(type, ModelException.IdentifierType.NAME, name);
|
||||
|
||||
return found.get();
|
||||
|
@ -63,7 +63,7 @@ public class MixTypeService extends AbstractJavaService<MixType, MixTypeReposito
|
|||
* @return Le type de mélange correspondant au produit
|
||||
*/
|
||||
public MixType getByMaterial(Material material) {
|
||||
Optional<MixType> found = dao.findByMaterial(material);
|
||||
Optional<MixType> found = repository.findByMaterial(material);
|
||||
if (found.isEmpty())
|
||||
throw new EntityNotFoundException(type, ModelException.IdentifierType.OTHER, MixType.IDENTIFIER_MATERIAL_NAME, material);
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.RecipeEditorFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.RecipeExplorerFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.files.ImagesService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.RecipeRepository;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.dto.RecipeEditorFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.dto.RecipeExplorerFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.files.ImagesService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.repository.RecipeRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -30,7 +30,7 @@ public class RecipeService extends AbstractJavaService<Recipe, RecipeRepository>
|
|||
|
||||
@Autowired
|
||||
public void setRecipeDao(RecipeRepository recipeRepository) {
|
||||
this.dao = recipeRepository;
|
||||
this.repository = recipeRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
|
@ -60,7 +60,7 @@ public class RecipeService extends AbstractJavaService<Recipe, RecipeRepository>
|
|||
* @return S'il y a une recette liée à la compagnie
|
||||
*/
|
||||
public boolean existsByCompany(Company company) {
|
||||
return dao.existsByCompany(company);
|
||||
return repository.existsByCompany(company);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ public class RecipeService extends AbstractJavaService<Recipe, RecipeRepository>
|
|||
* @return Toutes les recettes pour la compagnie
|
||||
*/
|
||||
public Collection<Recipe> getAllByCompany(Company company) {
|
||||
return dao.findAllByCompany(company);
|
||||
return repository.findAllByCompany(company);
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,9 +1,9 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.service.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.RecipeStep;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.StepRepository;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.RecipeStep;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.AbstractJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.repository.StepRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -20,7 +20,7 @@ public class StepService extends AbstractJavaService<RecipeStep, StepRepository>
|
|||
|
||||
@Autowired
|
||||
public void setStepDao(StepRepository stepRepository) {
|
||||
this.dao = stepRepository;
|
||||
this.repository = stepRepository;
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,6 +1,6 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.utils;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.utils;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.Preferences;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.config.Preferences;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.utils;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.utils;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.*;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MixFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MixTypeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.*;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.dto.MixFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MixTypeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class MixBuilder {
|
||||
|
||||
private MixTypeService mixTypeService;
|
||||
private MaterialService materialService;
|
||||
private MaterialJavaService materialService;
|
||||
|
||||
private Long id;
|
||||
private Recipe recipe;
|
||||
|
@ -21,7 +21,7 @@ public class MixBuilder {
|
|||
|
||||
private Map<String, Float> quantities = new LinkedHashMap<>();
|
||||
|
||||
public MixBuilder(MixTypeService mixTypeService, MaterialService materialService) {
|
||||
public MixBuilder(MixTypeService mixTypeService, MaterialJavaService materialService) {
|
||||
this.mixTypeService = mixTypeService;
|
||||
this.materialService = materialService;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.utils;
|
||||
package dev.fyloz.trial.colorrecipesexplorer.utils;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths;
|
||||
import lombok.AllArgsConstructor;
|
|
@ -1,7 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.utils.ControllerUtils
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode
|
||||
import dev.fyloz.trial.colorrecipesexplorer.utils.ControllerUtils
|
||||
import org.springframework.web.servlet.ModelAndView
|
||||
|
||||
fun modelAndView(model: ModelAndView = ModelAndView(), op: ModelAndView.() -> Unit = {}) = model.apply {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.PasswordService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.PasswordService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.RecipeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.MediaType;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.TooLowQuantityException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.JSONResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.InventoryDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.InventoryService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialTypeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.TooLowQuantityException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.JSONResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.dto.InventoryDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.InventoryService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialTypeJavaService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -32,11 +32,11 @@ import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.USE_INVENTOR
|
|||
public class InventoryController {
|
||||
|
||||
private InventoryService inventoryService;
|
||||
private MaterialService materialService;
|
||||
private MaterialTypeService materialTypeService;
|
||||
private MaterialJavaService materialService;
|
||||
private MaterialTypeJavaService materialTypeService;
|
||||
|
||||
@Autowired
|
||||
public InventoryController(InventoryService inventoryService, MaterialService materialService, MaterialTypeService materialTypeService) {
|
||||
public InventoryController(InventoryService inventoryService, MaterialJavaService materialService, MaterialTypeJavaService materialTypeService) {
|
||||
this.inventoryService = inventoryService;
|
||||
this.materialService = materialService;
|
||||
this.materialTypeService = materialTypeService;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.files.MarkdownFilesService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MixService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.files.MarkdownFilesService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MixService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.RecipeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.JSONResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.RecipeExplorerFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.JSONResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.dto.RecipeExplorerFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.RecipeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.MediaType;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.CompanyService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.CompanyService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.MediaType;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
//package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators;
|
||||
//
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.core.exception.SimdutException;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialTypeService;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.services.model.MaterialService;
|
||||
//import dev.fyloz.trial.colorrecipesexplorer.services.model.MaterialTypeService;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.http.MediaType;
|
||||
//import org.springframework.lang.Nullable;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.SimdutException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialTypeService
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialSaveDto
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialJavaService
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialTypeJavaService
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.CREATOR_MATERIAL
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.message
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.modelAndView
|
||||
|
@ -21,7 +22,7 @@ import javax.validation.Valid
|
|||
|
||||
@Controller
|
||||
@Profile("thymeleaf")
|
||||
class MaterialCreatorController(val materialService: MaterialService, val materialTypeService: MaterialTypeService) {
|
||||
class MaterialCreatorController(val materialService: MaterialJavaService, val materialTypeService: MaterialTypeJavaService) {
|
||||
@GetMapping(CREATOR_MATERIAL)
|
||||
fun getPage(model: ModelAndView, @RequestParam(required = false) material: Material? = null): ModelAndView {
|
||||
return modelAndView(model) {
|
||||
|
@ -35,7 +36,7 @@ class MaterialCreatorController(val materialService: MaterialService, val materi
|
|||
fun createMaterial(@Valid material: Material, simdut: MultipartFile): ModelAndView {
|
||||
return getPage(modelAndView {
|
||||
try {
|
||||
materialService.save(material, simdut)
|
||||
materialService.save(MaterialSaveDto(material.name, material.inventoryQuantity, material.materialType!!, simdut))
|
||||
message(ResponseCode.SUCCESS_SAVING_MATERIAL, material.name)
|
||||
} catch (ex: EntityAlreadyExistsException) {
|
||||
message(ResponseCode.MATERIAL_ALREADY_EXIST, material.name)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialTypeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.utils.ControllerUtils;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialTypeJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.utils.ControllerUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -24,10 +24,10 @@ import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.INDEX;
|
|||
@Profile("thymeleaf")
|
||||
public class MaterialTypeCreatorController {
|
||||
|
||||
private MaterialTypeService materialTypeService;
|
||||
private MaterialTypeJavaService materialTypeService;
|
||||
|
||||
@Autowired
|
||||
public MaterialTypeCreatorController(MaterialTypeService materialTypeService) {
|
||||
public MaterialTypeCreatorController(MaterialTypeJavaService materialTypeService) {
|
||||
this.materialTypeService = materialTypeService;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MixFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.ServiceKt;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.*;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.dto.MixFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.ServiceKt;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -31,11 +31,11 @@ public class MixCreatorController {
|
|||
|
||||
private MixService mixService;
|
||||
private RecipeService recipeService;
|
||||
private MaterialService materialService;
|
||||
private MaterialTypeService materialTypeService;
|
||||
private MaterialJavaService materialService;
|
||||
private MaterialTypeJavaService materialTypeService;
|
||||
|
||||
@Autowired
|
||||
public MixCreatorController(MixService mixService, RecipeService recipeService, MaterialService materialService, MixTypeService mixTypeService, MaterialTypeService materialTypeService) {
|
||||
public MixCreatorController(MixService mixService, RecipeService recipeService, MaterialJavaService materialService, MixTypeService mixTypeService, MaterialTypeJavaService materialTypeService) {
|
||||
this.mixService = mixService;
|
||||
this.recipeService = recipeService;
|
||||
this.materialService = materialService;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.CompanyService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.CompanyService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.RecipeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.editors;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.SimdutException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialTypeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialUpdateDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialTypeJavaService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -25,11 +26,11 @@ import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.*;
|
|||
@Profile("thymeleaf")
|
||||
public class MaterialEditorController {
|
||||
|
||||
private MaterialService materialService;
|
||||
private MaterialTypeService materialTypeService;
|
||||
private MaterialJavaService materialService;
|
||||
private MaterialTypeJavaService materialTypeService;
|
||||
|
||||
@Autowired
|
||||
public MaterialEditorController(MaterialService materialService, MaterialTypeService materialTypeService) {
|
||||
public MaterialEditorController(MaterialJavaService materialService, MaterialTypeJavaService materialTypeService) {
|
||||
this.materialService = materialService;
|
||||
this.materialTypeService = materialTypeService;
|
||||
}
|
||||
|
@ -92,7 +93,7 @@ public class MaterialEditorController {
|
|||
|
||||
try {
|
||||
Material material = materialService.getById(id);
|
||||
materialService.update(material, simdut);
|
||||
materialService.update(new MaterialUpdateDto(material.getId(), material.getName(), material.getInventoryQuantity(), material.getMaterialType(), simdut));
|
||||
} catch (EntityNotFoundException ex) {
|
||||
return getSimdutPage(
|
||||
modelResponseBuilder.addResponseCode(ResponseCode.MATERIAL_NOT_FOUND, id).build(),
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.editors;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.CannotEditDefaultMaterialTypeException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MaterialTypeEditorDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialTypeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.CannotEditDefaultMaterialTypeException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.dto.MaterialTypeEditorDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.service.model.MaterialTypeJavaService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialTypeKt;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -25,10 +25,10 @@ import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.*;
|
|||
@Profile("thymeleaf")
|
||||
public class MaterialTypeEditorController {
|
||||
|
||||
private MaterialTypeService materialTypeService;
|
||||
private MaterialTypeJavaService materialTypeService;
|
||||
|
||||
@Autowired
|
||||
public MaterialTypeEditorController(MaterialTypeService materialTypeService) {
|
||||
public MaterialTypeEditorController(MaterialTypeJavaService materialTypeService) {
|
||||
this.materialTypeService = materialTypeService;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class MaterialTypeEditorController {
|
|||
} catch (EntityAlreadyExistsException ex) {
|
||||
if (ModelException.IdentifierType.NAME.equals(ex.getIdentifierType()))
|
||||
responseBuilder.addResponseCode(ResponseCode.MATERIAL_TYPE_ALREADY_EXIST, materialTypeDto.getMaterialType().getName());
|
||||
else if (ex.getIdentifierName().equals(MaterialType.IDENTIFIER_PREFIX_NAME))
|
||||
else if (MaterialTypeKt.IDENTIFIER_PREFIX_NAME.equals(ex.getIdentifierName()))
|
||||
responseBuilder.addResponseCode(ResponseCode.MATERIAL_TYPE_ALREADY_EXIST_PREFIX, materialTypeDto.getMaterialType().getPrefix());
|
||||
} catch(CannotEditDefaultMaterialTypeException ex) {
|
||||
responseBuilder.addResponseCode(ResponseCode.CANNOT_EDIT_DEFAULT_MATERIAL_TYPE);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue