Skip to content

Commit

Permalink
Feature/conluz 74 (#75)
Browse files Browse the repository at this point in the history
* [conluz-74] Generated ER diagram to represent conluz_db database visually with an image and in dbml format

* [conluz-74] Replaced user by supply in plants. Added field isThirdParty on supply datadis fields. Added prefix 'datadis' to supply datadis fields

* [conluz-74] Adapted method to retrieve Datadis consumptions to manage supplies that are not third party authorized supplies

* [conluz-74] Supported isThirdParty setting for get and update supplies
  • Loading branch information
viktorKhan authored Jun 11, 2024
1 parent a1cf748 commit 92294f0
Show file tree
Hide file tree
Showing 46 changed files with 713 additions and 431 deletions.
88 changes: 88 additions & 0 deletions docs/db/er/conluz_db.dbml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Use DBML to define your database structure
// Docs: https://dbml.dbdiagram.io/docs

Table "config" {
"id" uuid [pk, not null]
"default_admin_user_initialized" boolean [not null, default: false]
}

Table "databasechangelog" {
"id" "character varying(255)" [not null]
"author" "character varying(255)" [not null]
"filename" "character varying(255)" [not null]
"dateexecuted" timestamp [not null]
"orderexecuted" integer [not null]
"exectype" "character varying(10)" [not null]
"md5sum" "character varying(35)"
"description" "character varying(255)"
"comments" "character varying(255)"
"tag" "character varying(255)"
"liquibase" "character varying(20)"
"contexts" "character varying(255)"
"labels" "character varying(255)"
"deployment_id" "character varying(10)"
}

Table "databasechangeloglock" {
"id" integer [pk, not null]
"locked" boolean [not null]
"lockgranted" timestamp
"lockedby" "character varying(255)"
}

Table "datadis_config" {
"id" uuid [pk, not null]
"username" text
"password" text
}

Table "huawei_config" {
"id" uuid [pk, not null]
"username" text
"password" text
}

Table "users" {
"id" uuid [pk, not null]
"personal_id" "character varying(250)" [not null]
"number" integer [not null]
"password" "character varying(250)" [not null]
"full_name" "character varying(250)" [not null]
"address" "character varying(250)"
"phone_number" "character varying(250)"
"email" "character varying(250)" [not null]
"role" "character varying(250)" [not null]
"enabled" boolean [not null]
}

Table "plants" {
"id" uuid [pk, not null]
"name" text [not null]
"code" text [not null]
"address" text [not null]
"description" text
"inverter_provider" text [not null]
"total_power" doubleprecision [not null]
"connection_date" date
"supply_id" uuid
}
Ref "plants_supply_id_fk":"supplies"."id" < "plants"."supply_id"

Table "supplies" {
"id" uuid [pk, not null]
"code" "character varying(250)" [not null]
"user_id" uuid
"name" "character varying(250)"
"address" "character varying(250)" [not null]
"partition_coefficient" doubleprecision [not null]
"enabled" boolean [not null]
"shelly_mac" "character varying(250)"
"shelly_id" "character varying(250)"
"shelly_mqtt_prefix" "character varying(250)"
"datadis_is_third_party" bool
"datadis_valid_date_from" date
"datadis_distributor" "character varying(250)"
"datadis_distributor_code" "character varying(250)"
"datadis_point_type" integer
}
Ref "supplies_user_id_fk":"users"."id" < "supplies"."user_id"
Binary file added docs/db/er/conluz_db.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.lucoenergia.conluz.domain.consumption.datadis.DistributorCode;
import org.lucoenergia.conluz.domain.admin.user.User;
import org.lucoenergia.conluz.infrastructure.shared.uuid.ValidUUID;

Expand All @@ -27,10 +26,11 @@ public class Supply {
@NotNull
private Boolean enabled;
// Data gathered from datadis.es
private LocalDate validDateFrom;
private String distributor;
private String distributorCode;
private Integer pointType;
private LocalDate datadisValidDateFrom;
private String datadisDistributor;
private String datadisDistributorCode;
private Integer datadisPointType;
private Boolean datadisIsThirdParty;
// Shelly settings
private String shellyMac;
private String shellyId;
Expand All @@ -44,10 +44,11 @@ private Supply(Builder builder) {
this.address = builder.address;
this.partitionCoefficient = builder.partitionCoefficient;
this.enabled = builder.enabled;
this.validDateFrom = builder.validDateFrom;
this.distributor = builder.distributor;
this.distributorCode = builder.distributorCode;
this.pointType = builder.pointType;
this.datadisValidDateFrom = builder.datadisValidDateFrom;
this.datadisDistributor = builder.datadisDistributor;
this.datadisDistributorCode = builder.datadisDistributorCode;
this.datadisPointType = builder.datadisPointType;
this.datadisIsThirdParty = builder.datadisIsThirdParty;
this.shellyId = builder.shellyId;
this.shellyMqttPrefix = builder.shellyMqttPrefix;
this.shellyMac = builder.shellyMac;
Expand All @@ -69,10 +70,11 @@ public static class Builder {
private String address;
private Float partitionCoefficient;
private Boolean enabled;
private LocalDate validDateFrom;
private String distributor;
private String distributorCode;
private Integer pointType;
private LocalDate datadisValidDateFrom;
private String datadisDistributor;
private String datadisDistributorCode;
private Integer datadisPointType;
private Boolean datadisIsThirdParty;
private String shellyMac;
private String shellyId;
private String shellyMqttPrefix;
Expand Down Expand Up @@ -113,23 +115,28 @@ public Builder withEnabled(Boolean enabled) {
return this;
}

public Builder withValidDateFrom(LocalDate validDateFrom) {
this.validDateFrom = validDateFrom;
public Builder withDatadisValidDateFrom(LocalDate validDateFrom) {
this.datadisValidDateFrom = validDateFrom;
return this;
}

public Builder withDistributor(String distributor) {
this.distributor = distributor;
public Builder withDatadisDistributor(String distributor) {
this.datadisDistributor = distributor;
return this;
}

public Builder withDistributorCode(String distributorCode) {
this.distributorCode = distributorCode;
public Builder withDatadisDistributorCode(String distributorCode) {
this.datadisDistributorCode = distributorCode;
return this;
}

public Builder withPointType(Integer pointType) {
this.pointType = pointType;
public Builder withDatadisPointType(Integer pointType) {
this.datadisPointType = pointType;
return this;
}

public Builder withDatadisIsThirdParty(Boolean isThirdParty) {
this.datadisIsThirdParty = isThirdParty;
return this;
}

Expand Down Expand Up @@ -185,40 +192,44 @@ public Boolean getEnabled() {
return enabled;
}

public LocalDate getValidDateFrom() {
return validDateFrom;
public LocalDate getDatadisValidDateFrom() {
return datadisValidDateFrom;
}

public String getDatadisDistributor() {
return datadisDistributor;
}

public String getDistributor() {
return distributor;
public String getDatadisDistributorCode() {
return datadisDistributorCode;
}

public String getDistributorCode() {
return distributorCode;
public Integer getDatadisPointType() {
return datadisPointType;
}

public Integer getPointType() {
return pointType;
public Boolean getDatadisIsThirdParty() {
return datadisIsThirdParty;
}

public void setAddress(String address) {
this.address = address;
}

public void setValidDateFrom(LocalDate validDateFrom) {
this.validDateFrom = validDateFrom;
public void setDatadisValidDateFrom(LocalDate datadisValidDateFrom) {
this.datadisValidDateFrom = datadisValidDateFrom;
}

public void setDistributor(String distributor) {
this.distributor = distributor;
public void setDatadisDistributor(String datadisDistributor) {
this.datadisDistributor = datadisDistributor;
}

public void setDistributorCode(String distributorCode) {
this.distributorCode = distributorCode;
public void setDatadisDistributorCode(String datadisDistributorCode) {
this.datadisDistributorCode = datadisDistributorCode;
}

public void setPointType(Integer pointType) {
this.pointType = pointType;
public void setDatadisPointType(Integer datadisPointType) {
this.datadisPointType = datadisPointType;
}

public String getShellyMac() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package org.lucoenergia.conluz.domain.admin.supply;

import org.lucoenergia.conluz.domain.shared.SupplyCode;
import org.lucoenergia.conluz.domain.shared.SupplyId;

public class SupplyNotFoundException extends RuntimeException {

private final SupplyId id;
private SupplyId id;
private SupplyCode code;

public SupplyNotFoundException(SupplyId id) {
this.id = id;
}

public SupplyNotFoundException(SupplyCode code) {
this.code = code;
}

public SupplyId getId() {
return id;
}

public SupplyCode getCode() {
return code;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.lucoenergia.conluz.domain.admin.supply.get;

import org.lucoenergia.conluz.domain.admin.supply.Supply;
import org.lucoenergia.conluz.domain.shared.SupplyCode;
import org.lucoenergia.conluz.domain.shared.SupplyId;
import org.lucoenergia.conluz.domain.shared.pagination.PagedRequest;
import org.lucoenergia.conluz.domain.shared.pagination.PagedResult;
Expand All @@ -13,6 +14,7 @@ public interface GetSupplyRepository {
long count();

Optional<Supply> findById(SupplyId id);
Optional<Supply> findByCode(SupplyCode code);

boolean existsById(SupplyId id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void synchronizeSupplies() {
Supply supply = allSupplies.get(datadisSupply.getCups());
if (supply != null) {
supply.setAddress(datadisSupply.getAddress());
supply.setDistributorCode(datadisSupply.getDistributorCode());
supply.setDistributor(datadisSupply.getDistributor());
supply.setPointType(datadisSupply.getPointType());
supply.setValidDateFrom(datadisSupply.getValidDateFrom() != null ?
supply.setDatadisDistributorCode(datadisSupply.getDistributorCode());
supply.setDatadisDistributor(datadisSupply.getDistributor());
supply.setDatadisPointType(datadisSupply.getPointType());
supply.setDatadisValidDateFrom(datadisSupply.getValidDateFrom() != null ?
dateConverter.convertStringToLocalDate(datadisSupply.getValidDateFrom()) :
null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void synchronizeConsumptions() {
LOGGER.info("Processing supply with ID: {}", supply.getId());

// Get validity date
LocalDate validDateFrom = supply.getValidDateFrom();
LocalDate validDateFrom = supply.getDatadisValidDateFrom();

// If the valid date is not present, we set the valid date on yesterday
if (validDateFrom == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.lucoenergia.conluz.domain.admin.user.User;
import org.lucoenergia.conluz.domain.admin.supply.Supply;
import org.lucoenergia.conluz.domain.production.InverterProvider;
import org.lucoenergia.conluz.infrastructure.shared.uuid.ValidUUID;

Expand Down Expand Up @@ -32,7 +32,7 @@ public class Plant {
private Double totalPower;
private LocalDate connectionDate;
@NotNull
private User user;
private Supply supply;

public UUID getId() {
return id;
Expand Down Expand Up @@ -66,12 +66,12 @@ public LocalDate getConnectionDate() {
return connectionDate;
}

public User getUser() {
return user;
public Supply getSupply() {
return supply;
}

public void setUser(User user) {
this.user = user;
public void setSupply(Supply supply) {
this.supply = supply;
}

public void initializeUuid() {
Expand All @@ -87,7 +87,7 @@ public static class Builder {
private InverterProvider inverterProvider;
private Double totalPower;
private LocalDate connectionDate;
private User user;
private Supply supply;

public Builder withId(UUID id) {
this.id = id;
Expand Down Expand Up @@ -129,8 +129,8 @@ public Builder withConnectionDate(LocalDate connectionDate) {
return this;
}

public Builder withUser(User user) {
this.user = user;
public Builder withSupply(Supply supply) {
this.supply = supply;
return this;
}

Expand All @@ -144,7 +144,7 @@ public Plant build() {
station.inverterProvider = this.inverterProvider;
station.totalPower = this.totalPower;
station.connectionDate = this.connectionDate;
station.user = this.user;
station.supply = this.supply;
return station;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.lucoenergia.conluz.domain.production.plant.create;

import org.lucoenergia.conluz.domain.production.plant.Plant;
import org.lucoenergia.conluz.domain.shared.UserId;
import org.lucoenergia.conluz.domain.shared.SupplyId;

public interface CreatePlantRepository {

Plant create(Plant supply, UserId id);
Plant create(Plant supply, SupplyId id);
}
Loading

0 comments on commit 92294f0

Please sign in to comment.