Skip to content

Commit

Permalink
Backend/service classes/s04 (#28)
Browse files Browse the repository at this point in the history
* init

* Service classes

New Methods have been added.

Issues: n/a

Signed-off-by: Kuzu<[email protected]>

---------

Signed-off-by: Kuzu<[email protected]>
  • Loading branch information
Serberx authored Jan 8, 2024
1 parent a286974 commit d67c4a2
Show file tree
Hide file tree
Showing 37 changed files with 738 additions and 308 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/samic/samic/Application.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.samic.samic;

import com.samic.samic.config.ORCLConfig;
import com.samic.samic.data.repositories.RepositoryUser;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.component.page.AppShellConfigurator;
Expand All @@ -10,6 +11,7 @@
import org.springframework.boot.autoconfigure.sql.init.SqlInitializationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;

import javax.sql.DataSource;

Expand All @@ -25,6 +27,7 @@
@Theme(value = "samic")
@ComponentScan(basePackages = {"com.samic.samic.data.repositories"})
@ComponentScan(basePackages = {"com.samic.samic.services"})
@Import(ORCLConfig.class)
public class Application implements AppShellConfigurator {

public static void main(String[] args) {
Expand All @@ -34,7 +37,7 @@ public static void main(String[] args) {

@Bean
SqlDataSourceScriptDatabaseInitializer dataSourceScriptDatabaseInitializer(DataSource dataSource,
SqlInitializationProperties properties, RepositoryUser repositoryUser) {
SqlInitializationProperties properties, RepositoryUser repositoryUser) {
// This bean ensures the database is only initialized when empty
return new SqlDataSourceScriptDatabaseInitializer(dataSource, properties) {
@Override
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/samic/samic/config/ORCLConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.samic.samic.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Configuration
@EnableJpaAuditing
public class ORCLConfig{
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.samic.samic.data.entity;

import jakarta.persistence.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.domain.Persistable;
import org.springframework.data.jpa.domain.AbstractPersistable;
import org.springframework.data.util.ProxyUtils;
import org.springframework.lang.Nullable;

import java.io.Serializable;
import java.time.LocalDateTime;

@MappedSuperclass
public class AbstractIdentityClass<PK extends Serializable> implements Persistable<PK>{

Expand Down Expand Up @@ -41,6 +45,13 @@ public boolean isNew() {
return null == getId();
}

@LastModifiedDate
private LocalDateTime lastModifiedAt;

@CreatedDate
private LocalDateTime createdAt;


@Override
public String toString() {
return String.format("Entity of type %s with id: %s", this.getClass().getName(), getId());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/samic/samic/data/entity/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public class Address{
private String city;


// @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
// @JoinColumn(foreignKey = @ForeignKey(name = "fk_address_to_storage"))
// private Storage storage;
// @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
// @JoinColumn(foreignKey = @ForeignKey(name = "fk_address_to_storage"))
// private Storage storage;

//
// public Integer getHouseNo(){
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/samic/samic/data/entity/CPE.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
@Table(name = "cpes")
public class CPE extends AbstractIdentityClass<Long>{

// @ManyToOne
//// @JoinColumn(name = "cpe")
// private StorageObject storageObject;

/*
relations
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/samic/samic/data/entity/ObjectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Table(name = "object_type")
@Table(name = "object_types")
public class ObjectType extends AbstractIdentityClass<Long>{

/*
relations
*/
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@OneToOne(mappedBy = "objectTypeName", fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
private StorageObject storageObject;


/*
attributes
*/
@Column(length = ConstantsDomain.DEFAULT_LENGTH)
@NotBlank
@Column(name="objectType_name", length = ConstantsDomain.DEFAULT_LENGTH)
private String name;
}
2 changes: 1 addition & 1 deletion src/main/java/com/samic/samic/data/entity/Producer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@NoArgsConstructor
@Data
@Builder
@Table(name = "producer")
@Table(name = "producers")
public class Producer extends AbstractIdentityClass<Long>{

/*
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/samic/samic/data/entity/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
@NoArgsConstructor
@Builder
@Embeddable
public class Profile /*extends AbstractPersistable<Long>*/{ //extend hier entferenen weil eine entity nicht
public class Profile { //extend hier entferenen weil eine entity nicht
// gleichzeitig ein embaddable sein kann!!!

/*
relations
*/
relations
*/
@Column(name = "user_name", length = ConstantsDomain.DEFAULT_LENGTH)
@NotBlank
private String username;
Expand Down
38 changes: 36 additions & 2 deletions src/main/java/com/samic/samic/data/entity/Reservation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.samic.samic.data.entity;

import com.samic.samic.data.constants.ConstantsDomain;
import com.samic.samic.exceptions.SamicException;
import jakarta.persistence.*;
import jakarta.validation.constraints.PastOrPresent;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -39,7 +40,6 @@ public class Reservation extends AbstractIdentityClass<Long>{
*/
@Embedded
@Column(name = "reserved_For")

private Customer customer;
@PastOrPresent
private LocalDateTime reservedAt;
Expand All @@ -48,12 +48,46 @@ public class Reservation extends AbstractIdentityClass<Long>{
private String reservedDescription;



@Column(name = "completed")
private Boolean completed;

@Column(name = "last_modified")
private LocalDateTime lastModified;



public void setReservedFrom(User reservedFrom){
if(reservedFrom != null){
if(this.getReservedFrom() == null){
this.reservedFrom = reservedFrom;
}else{
throw new SamicException("Reservation has already a User!");
}
}else{
throw new SamicException("Given User is null!");
}
}

public void setStorageObject(StorageObject storageObject){
if(storageObject != null){
if(this.getStorageObject() == null){
this.storageObject = storageObject;
}else{
throw new SamicException("Reservation has already set!");
}
}else{
throw new SamicException("Given StorageObject is null!");
}
}


public void setReservedAt(LocalDateTime reservedAt){
if(reservedAt != null){
if(this.getReservedAt() != null){
this.reservedAt = reservedAt;
}else{
throw new SamicException("Reservation Date has been already set!");
}
}
}
}
28 changes: 13 additions & 15 deletions src/main/java/com/samic/samic/data/entity/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
@AllArgsConstructor
@Builder
@Entity(name = "storages")

public class Storage extends AbstractIdentityClass<Long>{


/*
relations
*/
@OneToMany(mappedBy ="storage", fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
// @JoinColumn(name = "storage_objects")
private List<StorageObject> storageObject = new ArrayList<>();

@Column(name = "storage_Objekt_history")
Expand All @@ -44,17 +42,17 @@ public class Storage extends AbstractIdentityClass<Long>{
@NotBlank
private String name;

//
// public Storage addAddress(Address storageAddress){
// return this;
// }
//
// public Storage clearAddres(){
// address = null;
// return this;
// }
//
// public void setAddress(Address address){
// this.address = address;
// }
//
// public Storage addAddress(Address storageAddress){
// return this;
// }
//
// public Storage clearAddres(){
// address = null;
// return this;
// }
//
// public void setAddress(Address address){
// this.address = address;
// }
}
53 changes: 47 additions & 6 deletions src/main/java/com/samic/samic/data/entity/StorageObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.samic.samic.data.constants.ConstantsDomain;
import com.samic.samic.exceptions.SamicException;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.*;
Expand All @@ -20,9 +21,8 @@ public class StorageObject extends AbstractIdentityClass<Long>{
/*
relations
*/
@OneToOne(mappedBy = "storageObject", fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@JoinColumn(name = "object_type", foreignKey = @ForeignKey(name = "fk_objectType_2_storageObject"))
@NotNull
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@JoinColumn(name = "fk_object_type", foreignKey = @ForeignKey(name = "fk_objectType_2_storageObject"))
private ObjectType objectTypeName;

@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE}) //Shared Primary Key
Expand All @@ -34,11 +34,11 @@ public class StorageObject extends AbstractIdentityClass<Long>{
private CPE cpe;

@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) //Viele StorageObj. die auf einen SFP zeigen.
@JoinColumn(name = "SFP", foreignKey = @ForeignKey(name = "fk_sfp_2_storageObject"))
@JoinColumn(name = "fk_SFP", foreignKey = @ForeignKey(name = "fk_sfp_2_storageObject"))
private SFP sfp;

@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name = "supply", foreignKey = @ForeignKey(name = "fk_supply_2_storageObject"))
@JoinColumn(name = "fk_supply", foreignKey = @ForeignKey(name = "fk_supply_2_storageObject"))
private Supply supply;

@OneToMany(mappedBy = "storageObject", fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
Expand All @@ -55,7 +55,7 @@ public class StorageObject extends AbstractIdentityClass<Long>{

//Einseitige Beziehung
@ManyToOne(targetEntity = Storage.class,fetch = FetchType.LAZY,cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name = "fk_storageObject", foreignKey = @ForeignKey(name = "fk_storage_2_storageObject"))
@JoinColumn(name = "fk_storage", foreignKey = @ForeignKey(name = "fk_storage_2_storageObject"))
private Storage storage;

/*
Expand All @@ -76,6 +76,47 @@ public class StorageObject extends AbstractIdentityClass<Long>{
@Column(name = "project_device")
private Boolean projectDevice;

public void setReservation(Reservation reservation){
if(reservation != null){
if(this.getReservation() == null){
this.reservation = reservation;
}else{
throw new SamicException("Reservation has already been set!");
}
}else{
throw new SamicException("Given Reservation is null!");
}
}

public void setStorage(Storage storage){
if(storage != null){
this.storage = storage;
}
}

public void setCpe(CPE cpe){
if(cpe != null){
if(this.getSfp() == null){
this.cpe = cpe;
}
}
}

public void setSfp(SFP sfp){
if(sfp != null){
if(this.getCpe() == null){
this.sfp = sfp;
}
}
}

public void setSupply(Supply supply){
if(supply != null){
if(this.supply == null){
this.supply = supply;
}
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@NoArgsConstructor
@Builder
@Data
@Table(name = "storage_object_histories")
public class StorageObjectHistory extends AbstractIdentityClass<Long>{

/*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/samic/samic/data/entity/Supply.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "supply")
@Table(name = "supplies")
public class Supply extends AbstractIdentityClass<Long>{

/*
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/samic/samic/data/entity/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
@AllArgsConstructor // Error wenn erzeugt -> java: Konstruktor Type() ist bereits in Enumeration
// at.spengergasse.sj23247abcif.domain.Type definiert
public enum Type {
IP_PHONE("IP Phone", "IPP"),
ROUTER("Router", "Rt"),
SWITCH("Switch", "Sw"),
SFP("SFP", "SF"),
SUPPLY("Supply", "SP");
IP_PHONE("IP Phone", "IPP"),
ROUTER("Router", "Rt"),
SWITCH("Switch", "Sw"),
SFP("SFP", "SF"),
SUPPLY("Supply", "SP");

private String longVersion;
private String shortVersion;
private String longVersion;
private String shortVersion;
}
Loading

0 comments on commit d67c4a2

Please sign in to comment.