Fix DataCenter emission calculation: VM-level processing, authentication fixes, and type safety improvements
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,165 +1,204 @@
|
||||
package com.sgs.graphql.dataCenter.domain;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import com.sgs.graphql.area.domain.Area;
|
||||
import com.sgs.graphql.sector.domain.Sector;
|
||||
import com.sgs.graphql.subSector.domain.SubSector;
|
||||
import com.sgs.graphql.emissionSource.domain.EmissionSource;
|
||||
import com.sgs.graphql.emissionScope.domain.EmissionScope;
|
||||
import com.sgs.graphql.consuptionUnit.domain.ConsuptionUnit;
|
||||
import com.sgs.graphql.activitySubUnit.domain.ActivitySubUnit;
|
||||
import com.sgs.lib.dao.domain.BaseDomain;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "data_center")
|
||||
public class DataCenter extends BaseDomain {
|
||||
private String dataCenter;
|
||||
|
||||
@Column(unique = true)
|
||||
private Integer externalId;
|
||||
|
||||
private Integer number;
|
||||
private Area area;
|
||||
|
||||
private List<Project> projects = new ArrayList<>();
|
||||
private Sector sector;
|
||||
private SubSector subSector;
|
||||
private EmissionSource emissionSource;
|
||||
private EmissionScope emissionScope;
|
||||
private Double consuptionAmount;
|
||||
private ConsuptionUnit consuptionUnit;
|
||||
private ActivitySubUnit activitySubUnit;
|
||||
|
||||
|
||||
@Column(name = "data_center_name")
|
||||
@Transactional
|
||||
public String getDataCenter() {
|
||||
return dataCenter;
|
||||
}
|
||||
|
||||
public void setDataCenter(String dataCenter) {
|
||||
this.dataCenter = dataCenter;
|
||||
}
|
||||
|
||||
@Column(name = "external_id")
|
||||
public Integer getExternalId() {
|
||||
return externalId;
|
||||
}
|
||||
|
||||
@OneToMany(mappedBy = "dataCenter", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
||||
@JsonManagedReference
|
||||
public List<Project> getProjects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
public void setProjects(List<Project> projects) {
|
||||
this.projects = projects;
|
||||
}
|
||||
|
||||
public void setExternalId(Integer externalId) {
|
||||
this.externalId = externalId;
|
||||
}
|
||||
|
||||
@Column(name = "number")
|
||||
public Integer getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(Integer number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "sector_id")
|
||||
public Sector getSector() {
|
||||
return sector;
|
||||
}
|
||||
|
||||
public void setSector(Sector sector) {
|
||||
this.sector = sector;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "emission_scope_id")
|
||||
public EmissionScope getEmissionScope() {
|
||||
return emissionScope;
|
||||
}
|
||||
|
||||
public void setEmissionScope(EmissionScope emissionScope) {
|
||||
this.emissionScope = emissionScope;
|
||||
}
|
||||
|
||||
@Column(name = "consuption_amount")
|
||||
public Double getConsuptionAmount() {
|
||||
return consuptionAmount;
|
||||
}
|
||||
|
||||
public void setConsuptionAmount(Double consuptionAmount) {
|
||||
this.consuptionAmount = consuptionAmount;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "consuption_unit_id")
|
||||
public ConsuptionUnit getConsuptionUnit() {
|
||||
return consuptionUnit;
|
||||
}
|
||||
|
||||
public void setConsuptionUnit(ConsuptionUnit consuptionUnit) {
|
||||
this.consuptionUnit = consuptionUnit;
|
||||
}
|
||||
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "area_id")
|
||||
@JsonBackReference("area-datacenter")
|
||||
@JoinTable(name = "relation_datacenter_area",
|
||||
joinColumns = @JoinColumn(name = "datacenter_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "area_id", referencedColumnName = "id"))
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
public Area getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public void setArea(Area area) {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "sub_sector_id")
|
||||
public SubSector getSubSector() {
|
||||
return subSector;
|
||||
}
|
||||
|
||||
public void setSubSector(SubSector subSector) {
|
||||
this.subSector = subSector;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "emission_source_id")
|
||||
public EmissionSource getEmissionSource() {
|
||||
return emissionSource;
|
||||
}
|
||||
|
||||
public void setEmissionSource(EmissionSource emissionSource) {
|
||||
this.emissionSource = emissionSource;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "activity_sub_unit_id")
|
||||
public ActivitySubUnit getActivitySubUnit() {
|
||||
return activitySubUnit;
|
||||
}
|
||||
|
||||
public void setActivitySubUnit(ActivitySubUnit activitySubUnit) {
|
||||
this.activitySubUnit = activitySubUnit;
|
||||
}
|
||||
package com.sgs.graphql.dataCenter.domain;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import com.sgs.graphql.area.domain.Area;
|
||||
import com.sgs.graphql.sector.domain.Sector;
|
||||
import com.sgs.graphql.subSector.domain.SubSector;
|
||||
import com.sgs.graphql.emissionSource.domain.EmissionSource;
|
||||
import com.sgs.graphql.emissionScope.domain.EmissionScope;
|
||||
import com.sgs.graphql.consuptionUnit.domain.ConsuptionUnit;
|
||||
import com.sgs.graphql.activitySubUnit.domain.ActivitySubUnit;
|
||||
import com.sgs.lib.dao.domain.BaseDomain;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "data_center")
|
||||
public class DataCenter extends BaseDomain {
|
||||
private String dataCenter;
|
||||
|
||||
@Column(unique = true)
|
||||
private Integer externalId;
|
||||
|
||||
private Integer number;
|
||||
private String ayposURL;
|
||||
private String address;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Area area;
|
||||
|
||||
private List<Project> projects = new ArrayList<>();
|
||||
private Sector sector;
|
||||
private SubSector subSector;
|
||||
private EmissionSource emissionSource;
|
||||
private EmissionScope emissionScope;
|
||||
private Double consuptionAmount;
|
||||
private ConsuptionUnit consuptionUnit;
|
||||
private ActivitySubUnit activitySubUnit;
|
||||
|
||||
|
||||
@Column(name = "data_center_name")
|
||||
@Transactional
|
||||
public String getDataCenter() {
|
||||
return dataCenter;
|
||||
}
|
||||
|
||||
public void setDataCenter(String dataCenter) {
|
||||
this.dataCenter = dataCenter;
|
||||
}
|
||||
|
||||
@Column(name = "external_id")
|
||||
public Integer getExternalId() {
|
||||
return externalId;
|
||||
}
|
||||
|
||||
@OneToMany(mappedBy = "dataCenter", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
||||
@JsonManagedReference
|
||||
public List<Project> getProjects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
public void setProjects(List<Project> projects) {
|
||||
this.projects = projects;
|
||||
}
|
||||
|
||||
public void setExternalId(Integer externalId) {
|
||||
this.externalId = externalId;
|
||||
}
|
||||
|
||||
@Column(name = "number")
|
||||
public Integer getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(Integer number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Column(name = "aypos_url")
|
||||
public String getAyposURL() {
|
||||
return ayposURL;
|
||||
}
|
||||
|
||||
public void setAyposURL(String ayposURL) {
|
||||
this.ayposURL = ayposURL;
|
||||
}
|
||||
|
||||
@Column(name = "address")
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Column(name = "latitude")
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
@Column(name = "longitude")
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "sector_id")
|
||||
public Sector getSector() {
|
||||
return sector;
|
||||
}
|
||||
|
||||
public void setSector(Sector sector) {
|
||||
this.sector = sector;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "emission_scope_id")
|
||||
public EmissionScope getEmissionScope() {
|
||||
return emissionScope;
|
||||
}
|
||||
|
||||
public void setEmissionScope(EmissionScope emissionScope) {
|
||||
this.emissionScope = emissionScope;
|
||||
}
|
||||
|
||||
@Column(name = "consuption_amount")
|
||||
public Double getConsuptionAmount() {
|
||||
return consuptionAmount;
|
||||
}
|
||||
|
||||
public void setConsuptionAmount(Double consuptionAmount) {
|
||||
this.consuptionAmount = consuptionAmount;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "consuption_unit_id")
|
||||
public ConsuptionUnit getConsuptionUnit() {
|
||||
return consuptionUnit;
|
||||
}
|
||||
|
||||
public void setConsuptionUnit(ConsuptionUnit consuptionUnit) {
|
||||
this.consuptionUnit = consuptionUnit;
|
||||
}
|
||||
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "area_id")
|
||||
@JsonBackReference("area-datacenter")
|
||||
@JoinTable(name = "relation_datacenter_area",
|
||||
joinColumns = @JoinColumn(name = "datacenter_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "area_id", referencedColumnName = "id"))
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
public Area getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public void setArea(Area area) {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "sub_sector_id")
|
||||
public SubSector getSubSector() {
|
||||
return subSector;
|
||||
}
|
||||
|
||||
public void setSubSector(SubSector subSector) {
|
||||
this.subSector = subSector;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "emission_source_id")
|
||||
public EmissionSource getEmissionSource() {
|
||||
return emissionSource;
|
||||
}
|
||||
|
||||
public void setEmissionSource(EmissionSource emissionSource) {
|
||||
this.emissionSource = emissionSource;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "activity_sub_unit_id")
|
||||
public ActivitySubUnit getActivitySubUnit() {
|
||||
return activitySubUnit;
|
||||
}
|
||||
|
||||
public void setActivitySubUnit(ActivitySubUnit activitySubUnit) {
|
||||
this.activitySubUnit = activitySubUnit;
|
||||
}
|
||||
}
|
||||
@@ -1,71 +1,66 @@
|
||||
package com.sgs.graphql.dataCenter.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import com.sgs.lib.dao.domain.BaseDomain;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "physical_machine")
|
||||
public class PhysicalMachine extends BaseDomain {
|
||||
private String status;
|
||||
private String name;
|
||||
private Double powerConsumption;
|
||||
private Vms vms;
|
||||
private Project project;
|
||||
//private DataCenter dataCenter;
|
||||
//private Project project;
|
||||
//private Zone zone;
|
||||
|
||||
@Column(name = "status")
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Column(name = "name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Column(name = "power_consumption", nullable = false)
|
||||
public Double getPowerConsumption() {
|
||||
return powerConsumption;
|
||||
}
|
||||
|
||||
public void setPowerConsumption(Double powerConsumption) {
|
||||
this.powerConsumption = powerConsumption;
|
||||
}
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "vms_id")
|
||||
@JsonManagedReference
|
||||
public Vms getVms() {
|
||||
return vms;
|
||||
}
|
||||
|
||||
public void setVms(Vms vms) {
|
||||
this.vms = vms;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "project_id")
|
||||
@JsonBackReference
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
|
||||
package com.sgs.graphql.dataCenter.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import com.sgs.lib.dao.domain.BaseDomain;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "physical_machine")
|
||||
public class PhysicalMachine extends BaseDomain {
|
||||
private String status;
|
||||
private String name;
|
||||
private Double powerConsumption;
|
||||
private Vms vms;
|
||||
private Project project;
|
||||
|
||||
@Column(name = "status")
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Column(name = "name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Column(name = "power_consumption", nullable = false)
|
||||
public Double getPowerConsumption() {
|
||||
return powerConsumption;
|
||||
}
|
||||
|
||||
public void setPowerConsumption(Double powerConsumption) {
|
||||
this.powerConsumption = powerConsumption;
|
||||
}
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "vms_id")
|
||||
@JsonManagedReference
|
||||
public Vms getVms() {
|
||||
return vms;
|
||||
}
|
||||
|
||||
public void setVms(Vms vms) {
|
||||
this.vms = vms;
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "project_id")
|
||||
@JsonBackReference
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,8 @@ import com.sgs.lib.dao.domain.BaseDomain;
|
||||
public class Project extends BaseDomain{
|
||||
|
||||
private String name;
|
||||
|
||||
private List<PhysicalMachine> physicalMachines;
|
||||
|
||||
|
||||
@OneToMany(mappedBy = "project", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonManagedReference
|
||||
public List<PhysicalMachine> getPhysicalMachines() {
|
||||
@@ -30,7 +28,6 @@ public class Project extends BaseDomain{
|
||||
// This creates a foreign key in the `project` table
|
||||
private DataCenter dataCenter;
|
||||
|
||||
|
||||
@Column(name = "name")
|
||||
public String getName() {
|
||||
return name;
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
package com.sgs.graphql.dataCenter.mutation;
|
||||
|
||||
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||
import com.sgs.graphql.dataCenter.mutation.input.DataCenterInput;
|
||||
import com.sgs.graphql.dataCenter.repo.DataCenterRepo;
|
||||
import com.sgs.graphql.dataCenter.service.DataCenterService;
|
||||
import com.sgs.graphql.permission.domain.PermissionName;
|
||||
import com.sgs.graphql.systemHistory.enums.LogType;
|
||||
import com.sgs.graphql.systemHistory.mutation.SystemLogger;
|
||||
import com.sgs.graphql.userHistory.mutation.UserLogger;
|
||||
import com.sgs.graphql.userNotification.mutation.UserNotificationMutation;
|
||||
import com.sgs.graphql.area.domain.Area;
|
||||
import com.sgs.graphql.area.service.AreaService;
|
||||
import graphql.kickstart.tools.GraphQLMutationResolver;
|
||||
import graphql.schema.DataFetchingEnvironment;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class DataCenterMutation implements GraphQLMutationResolver {
|
||||
|
||||
private final DataCenterService dataCenterService;
|
||||
private final DataCenterRepo dataCenterRepo;
|
||||
private final AreaService areaService;
|
||||
private final SystemLogger systemLogger;
|
||||
private final UserLogger userLogger;
|
||||
private final UserNotificationMutation notificationMutation;
|
||||
|
||||
@Autowired
|
||||
public DataCenterMutation(DataCenterService dataCenterService, DataCenterRepo dataCenterRepo,
|
||||
AreaService areaService, SystemLogger systemLogger,
|
||||
UserLogger userLogger, UserNotificationMutation notificationMutation) {
|
||||
this.dataCenterService = dataCenterService;
|
||||
this.dataCenterRepo = dataCenterRepo;
|
||||
this.areaService = areaService;
|
||||
this.systemLogger = systemLogger;
|
||||
this.userLogger = userLogger;
|
||||
this.notificationMutation = notificationMutation;
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_CREATE + "')")
|
||||
@Transactional
|
||||
public DataCenter createDataCenter(DataCenterInput input, DataFetchingEnvironment environment) {
|
||||
DataCenter dataCenter = new DataCenter();
|
||||
|
||||
try {
|
||||
// Set basic properties
|
||||
dataCenter.setDataCenter(input.getDataCenter());
|
||||
dataCenter.setExternalId(input.getExternalId());
|
||||
dataCenter.setNumber(input.getNumber());
|
||||
dataCenter.setAyposURL(input.getAyposURL());
|
||||
dataCenter.setAddress(input.getAddress());
|
||||
dataCenter.setLatitude(input.getLatitude());
|
||||
dataCenter.setLongitude(input.getLongitude());
|
||||
|
||||
// Set area if provided
|
||||
if (input.getAreaId() != null) {
|
||||
Area area = areaService.findById(input.getAreaId())
|
||||
.orElseThrow(() -> new NoSuchElementException("Area not found with id: " + input.getAreaId()));
|
||||
dataCenter.setArea(area);
|
||||
}
|
||||
|
||||
// Set number if not provided
|
||||
if (dataCenter.getNumber() == null) {
|
||||
Integer maxNumber = dataCenterRepo.findMaxNumber();
|
||||
dataCenter.setNumber((maxNumber == null) ? 1 : maxNumber + 1);
|
||||
}
|
||||
|
||||
// Save the data center
|
||||
DataCenter savedDataCenter = dataCenterService.save(dataCenter);
|
||||
|
||||
// Log and notify
|
||||
String dataCenterName = input.getDataCenter();
|
||||
systemLogger.createSystemLog(LogType.INFO, dataCenterName + " adlı veri merkezi oluşturuldu");
|
||||
userLogger.createUserLog(LogType.INFO, dataCenterName + " adlı veri merkezi oluşturuldu", environment);
|
||||
notificationMutation.createNotification(environment, "Veri Merkezi",
|
||||
dataCenterName + " adlı veri merkezi oluşturuldu", "Yeni kayıt");
|
||||
|
||||
return savedDataCenter;
|
||||
|
||||
} catch (NoSuchElementException e) {
|
||||
systemLogger.createSystemLog(LogType.ERROR, "Veri merkezi oluşturulurken hata oluştu: " + e.getMessage());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
systemLogger.createSystemLog(LogType.ERROR, "Veri merkezi oluşturulurken hata oluştu: " + e.getMessage());
|
||||
throw new RuntimeException("Veri merkezi oluşturulurken hata oluştu", e);
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_UPDATE + "')")
|
||||
@Transactional
|
||||
public DataCenter updateDataCenter(UUID id, DataCenterInput input, DataFetchingEnvironment environment) {
|
||||
try {
|
||||
DataCenter dataCenter = dataCenterService.findById(id)
|
||||
.orElseThrow(() -> new NoSuchElementException("Data center not found with id: " + id));
|
||||
|
||||
// Update properties
|
||||
if (input.getDataCenter() != null) {
|
||||
dataCenter.setDataCenter(input.getDataCenter());
|
||||
}
|
||||
if (input.getExternalId() != null) {
|
||||
dataCenter.setExternalId(input.getExternalId());
|
||||
}
|
||||
if (input.getNumber() != null) {
|
||||
dataCenter.setNumber(input.getNumber());
|
||||
}
|
||||
if (input.getAyposURL() != null) {
|
||||
dataCenter.setAyposURL(input.getAyposURL());
|
||||
}
|
||||
if (input.getAddress() != null) {
|
||||
dataCenter.setAddress(input.getAddress());
|
||||
}
|
||||
if (input.getLatitude() != null) {
|
||||
dataCenter.setLatitude(input.getLatitude());
|
||||
}
|
||||
if (input.getLongitude() != null) {
|
||||
dataCenter.setLongitude(input.getLongitude());
|
||||
}
|
||||
|
||||
// Update area if provided
|
||||
if (input.getAreaId() != null) {
|
||||
Area area = areaService.findById(input.getAreaId())
|
||||
.orElseThrow(() -> new NoSuchElementException("Area not found with id: " + input.getAreaId()));
|
||||
dataCenter.setArea(area);
|
||||
}
|
||||
|
||||
// Save the updated data center
|
||||
DataCenter updatedDataCenter = dataCenterService.save(dataCenter);
|
||||
|
||||
// Log and notify
|
||||
String dataCenterName = dataCenter.getDataCenter();
|
||||
systemLogger.createSystemLog(LogType.INFO, dataCenterName + " adlı veri merkezi güncellendi");
|
||||
userLogger.createUserLog(LogType.INFO, dataCenterName + " adlı veri merkezi güncellendi", environment);
|
||||
notificationMutation.createNotification(environment, "Veri Merkezi",
|
||||
dataCenterName + " adlı veri merkezi güncellendi", "Güncelleme");
|
||||
|
||||
return updatedDataCenter;
|
||||
|
||||
} catch (NoSuchElementException e) {
|
||||
systemLogger.createSystemLog(LogType.ERROR, "Veri merkezi güncellenirken hata oluştu: " + e.getMessage());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
systemLogger.createSystemLog(LogType.ERROR, "Veri merkezi güncellenirken hata oluştu: " + e.getMessage());
|
||||
throw new RuntimeException("Veri merkezi güncellenirken hata oluştu", e);
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_DELETE + "')")
|
||||
@Transactional
|
||||
public Boolean deleteDataCenter(UUID id, DataFetchingEnvironment environment) {
|
||||
try {
|
||||
DataCenter dataCenter = dataCenterService.findById(id)
|
||||
.orElseThrow(() -> new NoSuchElementException("Data center not found with id: " + id));
|
||||
|
||||
// Delete the data center
|
||||
dataCenterService.delete(dataCenter);
|
||||
|
||||
// Log and notify
|
||||
String dataCenterName = dataCenter.getDataCenter();
|
||||
systemLogger.createSystemLog(LogType.INFO, dataCenterName + " adlı veri merkezi silindi");
|
||||
userLogger.createUserLog(LogType.INFO, dataCenterName + " adlı veri merkezi silindi", environment);
|
||||
notificationMutation.createNotification(environment, "Veri Merkezi",
|
||||
dataCenterName + " adlı veri merkezi silindi", "Silme");
|
||||
|
||||
return true;
|
||||
|
||||
} catch (NoSuchElementException e) {
|
||||
systemLogger.createSystemLog(LogType.ERROR, "Veri merkezi silinirken hata oluştu: " + e.getMessage());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
systemLogger.createSystemLog(LogType.ERROR, "Veri merkezi silinirken hata oluştu: " + e.getMessage());
|
||||
throw new RuntimeException("Veri merkezi silinirken hata oluştu", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.sgs.graphql.dataCenter.mutation.input;
|
||||
|
||||
import com.sgs.lib.dao.mutation.input.BaseCreateInput;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DataCenterInput extends BaseCreateInput {
|
||||
private String dataCenter;
|
||||
private Integer externalId;
|
||||
private String ayposURL;
|
||||
private Integer number;
|
||||
private String address;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private UUID areaId;
|
||||
|
||||
public String getDataCenter() {
|
||||
return dataCenter;
|
||||
}
|
||||
|
||||
public void setDataCenter(String dataCenter) {
|
||||
this.dataCenter = dataCenter;
|
||||
}
|
||||
|
||||
public Integer getExternalId() {
|
||||
return externalId;
|
||||
}
|
||||
|
||||
public void setExternalId(Integer externalId) {
|
||||
this.externalId = externalId;
|
||||
}
|
||||
|
||||
public String getAyposURL() {
|
||||
return ayposURL;
|
||||
}
|
||||
|
||||
public void setAyposURL(String ayposURL) {
|
||||
this.ayposURL = ayposURL;
|
||||
}
|
||||
|
||||
public Integer getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(Integer number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public UUID getAreaId() {
|
||||
return areaId;
|
||||
}
|
||||
|
||||
public void setAreaId(UUID areaId) {
|
||||
this.areaId = areaId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +1,74 @@
|
||||
package com.sgs.graphql.dataCenter.query;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.sgs.graphql.auth.service.AuthorizationService;
|
||||
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||
import com.sgs.graphql.dataCenter.query.pagination.DataCenterPageable;
|
||||
import com.sgs.graphql.dataCenter.repo.DataCenterRepo;
|
||||
import com.sgs.graphql.dataCenter.repo.criteria.DataCenterCriteria;
|
||||
import com.sgs.graphql.dataCenter.service.DataCenterService;
|
||||
import com.sgs.graphql.systemHistory.mutation.SystemLogger;
|
||||
import com.sgs.lib.dao.query.pagination.Pagination;
|
||||
import com.sgs.lib.dao.query.sort.SortBy;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
|
||||
@Component
|
||||
public class DataCenterQueryResolver implements GraphQLQueryResolver {
|
||||
|
||||
private final DataCenterService DataCenterService;
|
||||
private final DataCenterRepo dataCenterRepo;
|
||||
private final AuthorizationService authorizationService;
|
||||
private final SystemLogger systemLogger;
|
||||
|
||||
@Autowired
|
||||
public DataCenterQueryResolver(AuthorizationService authorizationService, SystemLogger systemLogger, DataCenterService DataCenterService, DataCenterRepo dataCenterRepo) {
|
||||
this.DataCenterService = DataCenterService;
|
||||
this.dataCenterRepo = dataCenterRepo;
|
||||
this.authorizationService = authorizationService;
|
||||
this.systemLogger = systemLogger;
|
||||
}
|
||||
|
||||
public DataCenter dataCenter(UUID id) {
|
||||
return DataCenterService.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<DataCenter> dataCenters(DataCenterCriteria criteria, List<SortBy> sortBy) {
|
||||
List<DataCenter> dataCenters = DataCenterService.filterWithSort(ObjectUtils.defaultIfNull(criteria, new DataCenterCriteria()),
|
||||
Sort.by(ObjectUtils.defaultIfNull(sortBy, new ArrayList<SortBy>())
|
||||
.stream()
|
||||
.map(SortBy::toOrder)
|
||||
.collect(Collectors.toList())));
|
||||
|
||||
return dataCenters;
|
||||
}
|
||||
|
||||
public DataCenterPageable paginateDataCenters(Pagination pagination, DataCenterCriteria criteria, List<SortBy> sortBy) {
|
||||
return new DataCenterPageable(DataCenterService.filterWithPaginate(ObjectUtils.defaultIfNull(criteria, new DataCenterCriteria()),
|
||||
Pagination.toPageRequest(pagination, sortBy)));
|
||||
}
|
||||
|
||||
|
||||
public Optional<DataCenter> getByNumber(Integer id) {
|
||||
return dataCenterRepo.findByNumber(id).stream().findFirst();
|
||||
}
|
||||
|
||||
}
|
||||
package com.sgs.graphql.dataCenter.query;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.sgs.graphql.auth.service.AuthorizationService;
|
||||
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||
import com.sgs.graphql.dataCenter.query.pagination.DataCenterPageable;
|
||||
import com.sgs.graphql.dataCenter.repo.DataCenterRepo;
|
||||
import com.sgs.graphql.dataCenter.repo.criteria.DataCenterCriteria;
|
||||
import com.sgs.graphql.dataCenter.service.DataCenterService;
|
||||
import com.sgs.graphql.permission.domain.PermissionName;
|
||||
import com.sgs.graphql.systemHistory.mutation.SystemLogger;
|
||||
import com.sgs.lib.dao.query.pagination.Pagination;
|
||||
import com.sgs.lib.dao.query.sort.SortBy;
|
||||
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
|
||||
@Component
|
||||
public class DataCenterQueryResolver implements GraphQLQueryResolver {
|
||||
|
||||
private final DataCenterService DataCenterService;
|
||||
private final DataCenterRepo dataCenterRepo;
|
||||
private final AuthorizationService authorizationService;
|
||||
private final SystemLogger systemLogger;
|
||||
|
||||
@Autowired
|
||||
public DataCenterQueryResolver(AuthorizationService authorizationService, SystemLogger systemLogger, DataCenterService DataCenterService, DataCenterRepo dataCenterRepo) {
|
||||
this.DataCenterService = DataCenterService;
|
||||
this.dataCenterRepo = dataCenterRepo;
|
||||
this.authorizationService = authorizationService;
|
||||
this.systemLogger = systemLogger;
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_READ + "')")
|
||||
public DataCenter dataCenter(UUID id) {
|
||||
return DataCenterService.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_LIST + "')")
|
||||
public List<DataCenter> dataCenters(DataCenterCriteria criteria, List<SortBy> sortBy) {
|
||||
List<DataCenter> dataCenters = DataCenterService.filterWithSort(ObjectUtils.defaultIfNull(criteria, new DataCenterCriteria()),
|
||||
Sort.by(ObjectUtils.defaultIfNull(sortBy, new ArrayList<SortBy>())
|
||||
.stream()
|
||||
.map(SortBy::toOrder)
|
||||
.collect(Collectors.toList())));
|
||||
|
||||
return dataCenters;
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.PAGINATE_DATACENTERS_GET + "')")
|
||||
public DataCenterPageable paginateDataCenters(Pagination pagination, DataCenterCriteria criteria, List<SortBy> sortBy) {
|
||||
return new DataCenterPageable(DataCenterService.filterWithPaginate(ObjectUtils.defaultIfNull(criteria, new DataCenterCriteria()),
|
||||
Pagination.toPageRequest(pagination, sortBy)));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_READ + "')")
|
||||
public Optional<DataCenter> getByNumber(Integer id) {
|
||||
return dataCenterRepo.findByNumber(id).stream().findFirst();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,8 +70,11 @@ public class PermissionDescription {
|
||||
public static final String SAVED_SURVEYS_PAGINATE = "Kaydedilmiş anketleri sayfalama ";
|
||||
public static final String SETTINGS_ACCESS = "Mail ayarlarını görüntüleme ve düzenleme";
|
||||
|
||||
public static final String DATA_CENTER_CREATE = "Veri Merkezi Ekleme";
|
||||
public static final String DATA_CENTER_DELETE = "Veri Merkezi Silme";
|
||||
public static final String DATA_CENTER_UPDATE = "Veri Merkezi Güncelleme";
|
||||
public static final String DATA_CENTER_READ = "Veri Merkezi Görüntüleme";
|
||||
public static final String DATA_CENTER_CREATE = "Veri merkezi oluşturma";
|
||||
public static final String DATA_CENTER_DELETE = "Veri merkezi silme";
|
||||
public static final String DATA_CENTER_UPDATE = "Veri merkezi güncelleme";
|
||||
public static final String DATA_CENTER_READ = "Veri merkezi görüntüleme";
|
||||
public static final String DATA_CENTER_LIST = "Veri merkezlerini listeleme";
|
||||
public static final String PAGINATE_DATACENTERS_GET = "Veri merkezlerini görüntüleme ve listeleme";
|
||||
|
||||
}
|
||||
|
||||
@@ -80,9 +80,11 @@ public class PermissionName {
|
||||
public static final String SAVED_SURVEYS_PAGINATE = "saved_surveys_paginate";
|
||||
public static final String SETTINGS_ACCESS = "settings_access";
|
||||
|
||||
public static final String DATA_CENTER_CREATE = "data_center_create";
|
||||
public static final String DATA_CENTER_DELETE = "data_center_delete";
|
||||
public static final String DATA_CENTER_UPDATE = "data_center_update";
|
||||
public static final String DATA_CENTER_READ = "data_center_read";
|
||||
public static final String DATA_CENTER_CREATE = "datacenter_create";
|
||||
public static final String DATA_CENTER_DELETE = "datacenter_delete";
|
||||
public static final String DATA_CENTER_UPDATE = "datacenter_update";
|
||||
public static final String DATA_CENTER_READ = "datacenter_get";
|
||||
public static final String DATA_CENTER_LIST = "datacenter_list";
|
||||
public static final String PAGINATE_DATACENTERS_GET = "paginate_datacenters_get";
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,15 +17,18 @@ security.jwt.token.secret-key=secret
|
||||
|
||||
app.survey.base-url=http://localhost.com
|
||||
|
||||
#spring.rabbitmq.host=188.132.198.145
|
||||
spring.rabbitmq.host=localhost
|
||||
spring.rabbitmq.host=188.132.198.145
|
||||
spring.rabbitmq.port=5672
|
||||
spring.rabbitmq.username=guest
|
||||
spring.rabbitmq.password=guest
|
||||
spring.rabbitmq.username=testuser
|
||||
spring.rabbitmq.password=JGasF24561AZv2894De
|
||||
# spring.rabbitmq.host=localhost
|
||||
# spring.rabbitmq.port=5672
|
||||
# spring.rabbitmq.username=guest
|
||||
# spring.rabbitmq.password=guest
|
||||
spring.rabbitmq.virtual-host=/
|
||||
spring.rabbitmq.connection-timeout=20000
|
||||
spring.rabbitmq.template.retry.enabled=true
|
||||
spring.rabbitmq.template.retry.max-attempts=3
|
||||
spring.rabbitmq.template.retry.initial-interval=1000ms
|
||||
|
||||
logging.level.org.springframework.amqp=DEBUG
|
||||
logging.level.org.springframework.amqp=DEBUG
|
||||
@@ -0,0 +1,5 @@
|
||||
extend type Mutation {
|
||||
createDataCenter(input: DataCenterInput!): DataCenter!
|
||||
updateDataCenter(id: ID!, input: DataCenterInput!): DataCenter!
|
||||
deleteDataCenter(id: ID!): Boolean!
|
||||
}
|
||||
@@ -1,84 +1,105 @@
|
||||
type DataCenter {
|
||||
id: ID
|
||||
dataCenter: String
|
||||
externalId: Int
|
||||
|
||||
emissionScope: EmissionScope
|
||||
sector: Sector
|
||||
subSector: SubSector
|
||||
activitySubUnit: ActivitySubUnit
|
||||
emissionSource: EmissionSource
|
||||
consuptionUnit: ConsuptionUnit
|
||||
consuptionAmount: Float
|
||||
|
||||
projects: [Project]
|
||||
area: Area
|
||||
number:Int
|
||||
}
|
||||
|
||||
type EmissionScope{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type Sector{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type SubSector{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type ActivitySubUnit{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type EmissionSource{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type ConsuptionUnit{
|
||||
tag: String
|
||||
}
|
||||
|
||||
|
||||
type Area {
|
||||
tag: String
|
||||
cityNames: [String]
|
||||
districtNames: [String]
|
||||
}
|
||||
|
||||
type Project {
|
||||
id: ID
|
||||
name: String
|
||||
physicalMachines: [PhysicalMachine]
|
||||
}
|
||||
|
||||
type PhysicalMachine {
|
||||
id: ID
|
||||
status: String
|
||||
name: String
|
||||
powerConsumption: Float
|
||||
vms: Vms
|
||||
}
|
||||
|
||||
type Vms {
|
||||
id: ID
|
||||
active: [Vm]
|
||||
inactive: [Vm]
|
||||
}
|
||||
|
||||
type Vm {
|
||||
id: ID
|
||||
status: String
|
||||
name: String
|
||||
power: Float
|
||||
calcOn: Boolean
|
||||
config: Config
|
||||
}
|
||||
|
||||
type Config {
|
||||
id: ID
|
||||
cpu: Int
|
||||
ram: Int
|
||||
disk: Int
|
||||
}
|
||||
type DataCenter {
|
||||
id: ID
|
||||
dataCenter: String
|
||||
externalId: Int
|
||||
ayposURL: String
|
||||
number: Int
|
||||
address: String
|
||||
latitude: Float
|
||||
longitude: Float
|
||||
|
||||
emissionScope: EmissionScope
|
||||
sector: Sector
|
||||
subSector: SubSector
|
||||
activitySubUnit: ActivitySubUnit
|
||||
emissionSource: EmissionSource
|
||||
consuptionUnit: ConsuptionUnit
|
||||
consuptionAmount: Float
|
||||
|
||||
projects: [Project]
|
||||
area: Area
|
||||
}
|
||||
|
||||
type EmissionScope{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type Sector{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type SubSector{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type ActivitySubUnit{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type EmissionSource{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type ConsuptionUnit{
|
||||
id: ID
|
||||
tag: String
|
||||
description: String
|
||||
deleted: Boolean
|
||||
}
|
||||
|
||||
|
||||
type Area {
|
||||
id: ID
|
||||
tag: String
|
||||
cityNames: [String]
|
||||
districtNames: [String]
|
||||
}
|
||||
|
||||
type Project {
|
||||
id: ID
|
||||
name: String
|
||||
physicalMachines: [PhysicalMachine]
|
||||
dataCenter: DataCenter
|
||||
}
|
||||
|
||||
type PhysicalMachine {
|
||||
id: ID
|
||||
status: String
|
||||
name: String
|
||||
powerConsumption: Float
|
||||
vms: Vms
|
||||
project: Project
|
||||
}
|
||||
|
||||
type Vms {
|
||||
id: ID
|
||||
active: [VM]
|
||||
inactive: [VM]
|
||||
}
|
||||
|
||||
type VM {
|
||||
id: ID
|
||||
status: String
|
||||
name: String
|
||||
power: Float
|
||||
calcOn: Boolean
|
||||
config: Config
|
||||
}
|
||||
|
||||
type Config {
|
||||
id: ID
|
||||
cpu: Int
|
||||
ram: Int
|
||||
disk: Int
|
||||
}
|
||||
|
||||
input DataCenterInput {
|
||||
dataCenter: String!
|
||||
externalId: Int
|
||||
ayposURL: String
|
||||
number: Int
|
||||
address: String
|
||||
latitude: Float
|
||||
longitude: Float
|
||||
areaId: ID
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user