forked from Abdulbari/sgeUpdated
Make the Datacenter module structure following the whole code structure
This commit is contained in:
39
docker-compose.yml
Normal file
39
docker-compose.yml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
services:
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: ./sge-backend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
env_file:
|
||||||
|
- ./config.conf
|
||||||
|
environment:
|
||||||
|
SPRING_PROFILES_ACTIVE: docker
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: ./sge-frontend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
env_file:
|
||||||
|
- ./config.conf
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
database:
|
||||||
|
image: postgres:15
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: sge
|
||||||
|
POSTGRES_USER: sge
|
||||||
|
POSTGRES_PASSWORD: 147
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
package com.sgs.graphql.dataCenter.domain;
|
package com.sgs.graphql.dataCenter.domain;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||||
import com.sgs.graphql.area.domain.Area;
|
import com.sgs.graphql.area.domain.Area;
|
||||||
@@ -14,7 +15,6 @@ import org.hibernate.annotations.LazyCollection;
|
|||||||
import org.hibernate.annotations.LazyCollectionOption;
|
import org.hibernate.annotations.LazyCollectionOption;
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -26,7 +26,7 @@ public class DataCenter extends BaseDomain {
|
|||||||
|
|
||||||
@Column(unique = true)
|
@Column(unique = true)
|
||||||
private Integer externalId;
|
private Integer externalId;
|
||||||
|
|
||||||
private Integer number;
|
private Integer number;
|
||||||
private Area area;
|
private Area area;
|
||||||
|
|
||||||
@@ -37,16 +37,14 @@ public class DataCenter extends BaseDomain {
|
|||||||
private EmissionScope emissionScope;
|
private EmissionScope emissionScope;
|
||||||
private Double consuptionAmount;
|
private Double consuptionAmount;
|
||||||
private ActivitySubUnit activitySubUnit;
|
private ActivitySubUnit activitySubUnit;
|
||||||
|
|
||||||
// New attributes
|
// New attributes
|
||||||
private String ayposURL;
|
private String ayposURL;
|
||||||
private String address;
|
private String address;
|
||||||
private Double latitude;
|
private Double latitude;
|
||||||
private Double longitude;
|
private Double longitude;
|
||||||
|
|
||||||
|
|
||||||
@Column(name = "data_center_name")
|
@Column(name = "data_center_name")
|
||||||
@Transactional
|
|
||||||
public String getDataCenter() {
|
public String getDataCenter() {
|
||||||
return dataCenter;
|
return dataCenter;
|
||||||
}
|
}
|
||||||
@@ -94,7 +92,6 @@ public class DataCenter extends BaseDomain {
|
|||||||
this.number = number;
|
this.number = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "sector_id")
|
@JoinColumn(name = "sector_id")
|
||||||
public Sector getSector() {
|
public Sector getSector() {
|
||||||
|
|||||||
@@ -1,18 +1,26 @@
|
|||||||
package com.sgs.graphql.dataCenter.mutation;
|
package com.sgs.graphql.dataCenter.mutation;
|
||||||
|
|
||||||
|
import com.sgs.exception.GraphQLCustomException;
|
||||||
import com.sgs.graphql.dataCenter.mutation.mapper.DataCenterMapper;
|
import com.sgs.graphql.dataCenter.mutation.mapper.DataCenterMapper;
|
||||||
import com.sgs.graphql.dataCenter.service.DataCenterService;
|
import com.sgs.graphql.dataCenter.service.DataCenterService;
|
||||||
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||||
import com.sgs.graphql.dataCenter.mutation.input.DataCenterCreateInput;
|
import com.sgs.graphql.dataCenter.mutation.input.DataCenterCreateInput;
|
||||||
import com.sgs.graphql.dataCenter.mutation.input.DataCenterUpdateInput;
|
import com.sgs.graphql.dataCenter.mutation.input.DataCenterUpdateInput;
|
||||||
import com.sgs.graphql.permission.domain.PermissionName;
|
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 graphql.kickstart.tools.GraphQLMutationResolver;
|
import graphql.kickstart.tools.GraphQLMutationResolver;
|
||||||
|
import graphql.schema.DataFetchingEnvironment;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Validated
|
@Validated
|
||||||
@@ -21,57 +29,128 @@ public class DataCenterMutation implements GraphQLMutationResolver {
|
|||||||
|
|
||||||
private final DataCenterService dataCenterService;
|
private final DataCenterService dataCenterService;
|
||||||
private final DataCenterMapper dataCenterMapper;
|
private final DataCenterMapper dataCenterMapper;
|
||||||
|
private final SystemLogger systemLogger;
|
||||||
|
private final UserLogger userLogger;
|
||||||
|
private final UserNotificationMutation notificationMutation;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DataCenterMutation(DataCenterService dataCenterService, DataCenterMapper dataCenterMapper) {
|
public DataCenterMutation(DataCenterService dataCenterService, DataCenterMapper dataCenterMapper,
|
||||||
|
SystemLogger systemLogger, UserLogger userLogger,
|
||||||
|
UserNotificationMutation notificationMutation) {
|
||||||
this.dataCenterService = dataCenterService;
|
this.dataCenterService = dataCenterService;
|
||||||
this.dataCenterMapper = dataCenterMapper;
|
this.dataCenterMapper = dataCenterMapper;
|
||||||
|
this.systemLogger = systemLogger;
|
||||||
|
this.userLogger = userLogger;
|
||||||
|
this.notificationMutation = notificationMutation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_CREATE + "')")
|
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_CREATE + "')")
|
||||||
public DataCenter createDataCenter(@Valid DataCenterCreateInput input) {
|
@Transactional
|
||||||
// Check for duplicate externalId
|
public DataCenter createDataCenter(@Valid DataCenterCreateInput input, DataFetchingEnvironment environment) {
|
||||||
if (input.getExternalId() != null && dataCenterService.existsByExternalId(input.getExternalId())) {
|
try {
|
||||||
throw new RuntimeException("This external id already exists: " + input.getExternalId());
|
// Check for duplicate externalId
|
||||||
|
if (input.getExternalId() != null && dataCenterService.existsByExternalId(input.getExternalId())) {
|
||||||
|
throw new GraphQLCustomException("2010", input.getExternalId().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
DataCenter dataCenter = dataCenterMapper.toEntity(input);
|
||||||
|
|
||||||
|
// Set auto-generated number if not provided
|
||||||
|
if (dataCenter.getNumber() == null) {
|
||||||
|
Integer maxNumber = dataCenterService.findMaxNumber();
|
||||||
|
dataCenter.setNumber((maxNumber == null) ? 1 : maxNumber + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataCenter savedDataCenter = dataCenterService.save(dataCenter);
|
||||||
|
|
||||||
|
// Log and notify
|
||||||
|
String dataCenterName = savedDataCenter.getDataCenter() != null ? savedDataCenter.getDataCenter()
|
||||||
|
: "DataCenter #" + savedDataCenter.getNumber();
|
||||||
|
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 (GraphQLCustomException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
systemLogger.createSystemLog(LogType.ERROR,
|
||||||
|
"Yeni veri merkezi oluşturulurken hata oluştu: " + e.getMessage());
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataCenter dataCenter = dataCenterMapper.toEntity(input);
|
|
||||||
|
|
||||||
// Set auto-generated number if not provided
|
|
||||||
if (dataCenter.getNumber() == null) {
|
|
||||||
Integer maxNumber = dataCenterService.getRepository().findMaxNumber();
|
|
||||||
dataCenter.setNumber((maxNumber == null) ? 1 : maxNumber + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataCenterService.save(dataCenter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_UPDATE + "')")
|
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_UPDATE + "')")
|
||||||
public DataCenter updateDataCenter(UUID id, @Valid DataCenterUpdateInput input) {
|
@Transactional
|
||||||
return dataCenterService.findById(id)
|
public DataCenter updateDataCenter(UUID id, @Valid DataCenterUpdateInput input,
|
||||||
.map(dataCenter -> {
|
DataFetchingEnvironment environment) {
|
||||||
// Check for duplicate externalId if it's being updated
|
try {
|
||||||
if (input.getExternalId() != null &&
|
DataCenter dataCenter = dataCenterService.findById(id)
|
||||||
!input.getExternalId().equals(dataCenter.getExternalId()) &&
|
.orElseThrow(() -> new NoSuchElementException("Data center not found with ID: " + id));
|
||||||
dataCenterService.existsByExternalId(input.getExternalId())) {
|
|
||||||
throw new RuntimeException("This external id already exists: " + input.getExternalId());
|
// Check for duplicate externalId if it's being updated
|
||||||
}
|
if (input.getExternalId() != null &&
|
||||||
return dataCenterService.update(dataCenterMapper.updateEntity(dataCenter, input));
|
!input.getExternalId().equals(dataCenter.getExternalId()) &&
|
||||||
})
|
dataCenterService.existsByExternalId(input.getExternalId())) {
|
||||||
.orElseThrow(() -> new RuntimeException("Data center not found with ID: " + id));
|
throw new GraphQLCustomException("2010", input.getExternalId().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
DataCenter updatedDataCenter = dataCenterService.update(dataCenterMapper.updateEntity(dataCenter, input));
|
||||||
|
|
||||||
|
// Log and notify
|
||||||
|
String dataCenterName = updatedDataCenter.getDataCenter() != null ? updatedDataCenter.getDataCenter()
|
||||||
|
: "DataCenter #" + updatedDataCenter.getNumber();
|
||||||
|
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 (GraphQLCustomException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
systemLogger.createSystemLog(LogType.ERROR, "Veri merkezi bulunamadı: " + id);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
systemLogger.createSystemLog(LogType.ERROR, "Veri merkezi güncellenirken hata oluştu: " + e.getMessage());
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_DELETE + "')")
|
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_DELETE + "')")
|
||||||
public Boolean deleteDataCenter(UUID id) {
|
@Transactional
|
||||||
|
public String deleteDataCenter(UUID id, DataFetchingEnvironment environment) {
|
||||||
|
String dataCenterName = "";
|
||||||
try {
|
try {
|
||||||
DataCenter dataCenter = dataCenterService.findById(id)
|
DataCenter dataCenter = dataCenterService.findById(id)
|
||||||
.orElseThrow(() -> new RuntimeException("Data center not found with ID: " + id));
|
.orElseThrow(() -> new NoSuchElementException("Data center not found with ID: " + id));
|
||||||
|
|
||||||
|
dataCenterName = dataCenter.getDataCenter() != null ? dataCenter.getDataCenter()
|
||||||
|
: "DataCenter #" + dataCenter.getNumber();
|
||||||
|
|
||||||
|
// Check if data center has physical machines or other dependencies
|
||||||
|
if (dataCenter.getPhysicalMachines() != null && !dataCenter.getPhysicalMachines().isEmpty()) {
|
||||||
|
String message = "Silinmeye çalışılan veri merkezinin fiziksel makineleri olduğu için silinememektedir";
|
||||||
|
systemLogger.createSystemLog(LogType.WARN, dataCenterName + ": " + message);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
dataCenterService.delete(dataCenter);
|
dataCenterService.delete(dataCenter);
|
||||||
return true;
|
|
||||||
|
// Log and notify
|
||||||
|
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 bulunamadı: " + id);
|
||||||
|
return "false";
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("DataCenter deletion error: " + e.getMessage());
|
systemLogger.createSystemLog(LogType.ERROR, "Veri merkezi silinirken hata oluştu: " + e.getMessage());
|
||||||
return false;
|
return "false";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,8 @@ import com.sgs.lib.dao.mutation.input.BaseUpdateInput;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
public class DataCenterUpdateInput extends BaseUpdateInput {
|
public class DataCenterUpdateInput extends BaseUpdateInput {
|
||||||
private String dataCenter;
|
private String dataCenter;
|
||||||
private Integer externalId;
|
private Integer externalId;
|
||||||
|
|||||||
@@ -11,17 +11,16 @@ import javax.transaction.Transactional;
|
|||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.sgs.graphql.auth.service.AuthorizationService;
|
|
||||||
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||||
import com.sgs.graphql.dataCenter.domain.PhysicalMachine;
|
import com.sgs.graphql.dataCenter.domain.PhysicalMachine;
|
||||||
import com.sgs.graphql.dataCenter.query.pagination.DataCenterPageable;
|
import com.sgs.graphql.dataCenter.query.pagination.DataCenterPageable;
|
||||||
import com.sgs.graphql.dataCenter.repo.DataCenterRepo;
|
|
||||||
import com.sgs.graphql.dataCenter.repo.PhysicalMachineRepo;
|
|
||||||
import com.sgs.graphql.dataCenter.repo.criteria.DataCenterCriteria;
|
import com.sgs.graphql.dataCenter.repo.criteria.DataCenterCriteria;
|
||||||
import com.sgs.graphql.dataCenter.service.DataCenterService;
|
import com.sgs.graphql.dataCenter.service.DataCenterService;
|
||||||
import com.sgs.graphql.systemHistory.mutation.SystemLogger;
|
import com.sgs.graphql.dataCenter.service.PhysicalMachineService;
|
||||||
|
import com.sgs.graphql.permission.domain.PermissionName;
|
||||||
import com.sgs.lib.dao.query.pagination.Pagination;
|
import com.sgs.lib.dao.query.pagination.Pagination;
|
||||||
import com.sgs.lib.dao.query.sort.SortBy;
|
import com.sgs.lib.dao.query.sort.SortBy;
|
||||||
|
|
||||||
@@ -30,48 +29,46 @@ import graphql.kickstart.tools.GraphQLQueryResolver;
|
|||||||
@Component
|
@Component
|
||||||
public class DataCenterQueryResolver implements GraphQLQueryResolver {
|
public class DataCenterQueryResolver implements GraphQLQueryResolver {
|
||||||
|
|
||||||
private final DataCenterService DataCenterService;
|
private final DataCenterService dataCenterService;
|
||||||
private final DataCenterRepo dataCenterRepo;
|
private final PhysicalMachineService physicalMachineService;
|
||||||
private final PhysicalMachineRepo physicalMachineRepo;
|
|
||||||
private final AuthorizationService authorizationService;
|
|
||||||
private final SystemLogger systemLogger;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DataCenterQueryResolver(AuthorizationService authorizationService, SystemLogger systemLogger, DataCenterService DataCenterService, DataCenterRepo dataCenterRepo, PhysicalMachineRepo physicalMachineRepo) {
|
public DataCenterQueryResolver(DataCenterService dataCenterService, PhysicalMachineService physicalMachineService) {
|
||||||
this.DataCenterService = DataCenterService;
|
this.dataCenterService = dataCenterService;
|
||||||
this.dataCenterRepo = dataCenterRepo;
|
this.physicalMachineService = physicalMachineService;
|
||||||
this.physicalMachineRepo = physicalMachineRepo;
|
|
||||||
this.authorizationService = authorizationService;
|
|
||||||
this.systemLogger = systemLogger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_READ + "')")
|
||||||
public DataCenter dataCenter(UUID id) {
|
public DataCenter dataCenter(UUID id) {
|
||||||
return DataCenterService.findById(id).orElse(null);
|
return dataCenterService.findById(id).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_READ + "')")
|
||||||
public List<DataCenter> dataCenters(DataCenterCriteria criteria, List<SortBy> sortBy) {
|
public List<DataCenter> dataCenters(DataCenterCriteria criteria, List<SortBy> sortBy) {
|
||||||
List<DataCenter> dataCenters = DataCenterService.filterWithSort(ObjectUtils.defaultIfNull(criteria, new DataCenterCriteria()),
|
return dataCenterService.filterWithSort(ObjectUtils.defaultIfNull(criteria, new DataCenterCriteria()),
|
||||||
Sort.by(ObjectUtils.defaultIfNull(sortBy, new ArrayList<SortBy>())
|
Sort.by(ObjectUtils.defaultIfNull(sortBy, new ArrayList<SortBy>())
|
||||||
.stream()
|
.stream()
|
||||||
.map(SortBy::toOrder)
|
.map(SortBy::toOrder)
|
||||||
.collect(Collectors.toList())));
|
.collect(Collectors.toList())));
|
||||||
|
|
||||||
return dataCenters;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataCenterPageable paginateDataCenters(Pagination pagination, DataCenterCriteria criteria, List<SortBy> sortBy) {
|
@PreAuthorize("hasAuthority('" + PermissionName.PAGINATE_DATACENTERS_GET + "')")
|
||||||
return new DataCenterPageable(DataCenterService.filterWithPaginate(ObjectUtils.defaultIfNull(criteria, new DataCenterCriteria()),
|
public DataCenterPageable paginateDataCenters(Pagination pagination, DataCenterCriteria criteria,
|
||||||
Pagination.toPageRequest(pagination, sortBy)));
|
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) {
|
public Optional<DataCenter> getByNumber(Integer number) {
|
||||||
return dataCenterRepo.findByNumber(id).stream().findFirst();
|
return dataCenterService.findByNumber(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_READ + "')")
|
||||||
public List<PhysicalMachine> physicalMachines(UUID datacenterId) {
|
public List<PhysicalMachine> physicalMachines(UUID datacenterId) {
|
||||||
return physicalMachineRepo.findByDatacenterId(datacenterId);
|
return physicalMachineService.findByDatacenterId(datacenterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package com.sgs.graphql.dataCenter.repo;
|
|||||||
|
|
||||||
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||||
import com.sgs.graphql.dataCenter.domain.DataCenterEmissionSource;
|
import com.sgs.graphql.dataCenter.domain.DataCenterEmissionSource;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import com.sgs.lib.dao.repo.BaseRepo;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
@@ -11,14 +12,14 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface DataCenterEmissionSourceRepo extends JpaRepository<DataCenterEmissionSource, String> {
|
public interface DataCenterEmissionSourceRepo extends BaseRepo<DataCenterEmissionSource> {
|
||||||
|
|
||||||
List<DataCenterEmissionSource> findByDataCenter(DataCenter dataCenter);
|
List<DataCenterEmissionSource> findByDataCenter(DataCenter dataCenter);
|
||||||
|
|
||||||
Optional<DataCenterEmissionSource> findByDataCenterAndIsDefaultTrue(DataCenter dataCenter);
|
Optional<DataCenterEmissionSource> findByDataCenterAndIsDefaultTrue(DataCenter dataCenter);
|
||||||
|
|
||||||
@Query("SELECT dces FROM DataCenterEmissionSource dces WHERE dces.dataCenter.id = :dataCenterId")
|
@Query("SELECT dces FROM DataCenterEmissionSource dces WHERE dces.dataCenter.id = :dataCenterId")
|
||||||
List<DataCenterEmissionSource> findByDataCenterId(@Param("dataCenterId") String dataCenterId);
|
List<DataCenterEmissionSource> findByDataCenterId(@Param("dataCenterId") String dataCenterId);
|
||||||
|
|
||||||
void deleteByDataCenter(DataCenter dataCenter);
|
void deleteByDataCenter(DataCenter dataCenter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.repo.criteria;
|
||||||
|
|
||||||
|
import com.sgs.lib.dao.repo.criteria.BaseCriteria;
|
||||||
|
|
||||||
|
public class DataCenterEmissionSourceCriteria extends BaseCriteria {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.repo.criteria;
|
||||||
|
|
||||||
|
import com.sgs.lib.dao.repo.criteria.BaseCriteria;
|
||||||
|
|
||||||
|
public class PhysicalMachineCriteria extends BaseCriteria {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.repo.criteria;
|
||||||
|
|
||||||
|
import com.sgs.lib.dao.repo.criteria.BaseCriteria;
|
||||||
|
|
||||||
|
public class VMCriteria extends BaseCriteria {
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.repo.criteria.spec;
|
||||||
|
|
||||||
|
import com.sgs.graphql.dataCenter.domain.DataCenterEmissionSource;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.criteria.DataCenterEmissionSourceCriteria;
|
||||||
|
import com.sgs.lib.dao.repo.criteria.spec.BaseCriteriaSpec;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DataCenterEmissionSourceCriteriaSpec
|
||||||
|
extends BaseCriteriaSpec<DataCenterEmissionSource, DataCenterEmissionSourceCriteria> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Specification<DataCenterEmissionSource> createForAll(DataCenterEmissionSourceCriteria criteria) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.repo.criteria.spec;
|
||||||
|
|
||||||
|
import com.sgs.graphql.dataCenter.domain.PhysicalMachine;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.criteria.PhysicalMachineCriteria;
|
||||||
|
import com.sgs.lib.dao.repo.criteria.spec.BaseCriteriaSpec;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PhysicalMachineCriteriaSpec extends BaseCriteriaSpec<PhysicalMachine, PhysicalMachineCriteria> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Specification<PhysicalMachine> createForAll(PhysicalMachineCriteria criteria) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.repo.criteria.spec;
|
||||||
|
|
||||||
|
import com.sgs.graphql.dataCenter.domain.VM;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.criteria.VMCriteria;
|
||||||
|
import com.sgs.lib.dao.repo.criteria.spec.BaseCriteriaSpec;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class VMCriteriaSpec extends BaseCriteriaSpec<VM, VMCriteria> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Specification<VM> createForAll(VMCriteria criteria) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.service;
|
||||||
|
|
||||||
|
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||||
|
import com.sgs.graphql.dataCenter.domain.DataCenterEmissionSource;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.DataCenterEmissionSourceRepo;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.criteria.DataCenterEmissionSourceCriteria;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.criteria.spec.DataCenterEmissionSourceCriteriaSpec;
|
||||||
|
import com.sgs.lib.dao.service.BaseService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DataCenterEmissionSourceService extends
|
||||||
|
BaseService<DataCenterEmissionSource, DataCenterEmissionSourceRepo, DataCenterEmissionSourceCriteria, DataCenterEmissionSourceCriteriaSpec> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DataCenterEmissionSourceService(DataCenterEmissionSourceRepo repository,
|
||||||
|
DataCenterEmissionSourceCriteriaSpec criteriaSpec) {
|
||||||
|
super(repository, criteriaSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DataCenterEmissionSource> findByDataCenter(DataCenter dataCenter) {
|
||||||
|
return getRepository().findByDataCenter(dataCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<DataCenterEmissionSource> findByDataCenterAndIsDefaultTrue(DataCenter dataCenter) {
|
||||||
|
return getRepository().findByDataCenterAndIsDefaultTrue(dataCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DataCenterEmissionSource> findByDataCenterId(String dataCenterId) {
|
||||||
|
return getRepository().findByDataCenterId(dataCenterId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteByDataCenter(DataCenter dataCenter) {
|
||||||
|
getRepository().deleteByDataCenter(dataCenter);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,15 +8,26 @@ import com.sgs.lib.dao.service.BaseService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DataCenterService extends BaseService<DataCenter, DataCenterRepo, DataCenterCriteria, DataCenterCriteriaSpec> {
|
public class DataCenterService
|
||||||
|
extends BaseService<DataCenter, DataCenterRepo, DataCenterCriteria, DataCenterCriteriaSpec> {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DataCenterService(DataCenterRepo repository, DataCenterCriteriaSpec criteriaSpec) {
|
public DataCenterService(DataCenterRepo repository, DataCenterCriteriaSpec criteriaSpec) {
|
||||||
super(repository, criteriaSpec);
|
super(repository, criteriaSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean existsByExternalId(Integer externalId) {
|
public boolean existsByExternalId(Integer externalId) {
|
||||||
return getRepository().existsByExternalId(externalId);
|
return getRepository().existsByExternalId(externalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<DataCenter> findByNumber(Integer number) {
|
||||||
|
return getRepository().findByNumber(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer findMaxNumber() {
|
||||||
|
return getRepository().findMaxNumber();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.service;
|
||||||
|
|
||||||
|
import com.sgs.graphql.dataCenter.domain.PhysicalMachine;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.PhysicalMachineRepo;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.criteria.PhysicalMachineCriteria;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.criteria.spec.PhysicalMachineCriteriaSpec;
|
||||||
|
import com.sgs.lib.dao.service.BaseService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PhysicalMachineService extends
|
||||||
|
BaseService<PhysicalMachine, PhysicalMachineRepo, PhysicalMachineCriteria, PhysicalMachineCriteriaSpec> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public PhysicalMachineService(PhysicalMachineRepo repository, PhysicalMachineCriteriaSpec criteriaSpec) {
|
||||||
|
super(repository, criteriaSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PhysicalMachine> findByDatacenterId(UUID datacenterId) {
|
||||||
|
return getRepository().findByDatacenterId(datacenterId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.service;
|
||||||
|
|
||||||
|
import com.sgs.graphql.dataCenter.domain.VM;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.VMRepo;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.criteria.VMCriteria;
|
||||||
|
import com.sgs.graphql.dataCenter.repo.criteria.spec.VMCriteriaSpec;
|
||||||
|
import com.sgs.lib.dao.service.BaseService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class VMService extends BaseService<VM, VMRepo, VMCriteria, VMCriteriaSpec> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public VMService(VMRepo repository, VMCriteriaSpec criteriaSpec) {
|
||||||
|
super(repository, criteriaSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<VM> findAllByVmName(String vmName) {
|
||||||
|
return getRepository().findAllByVmName(vmName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<VM> findFirstByVmNameOrderByIdDesc(String vmName) {
|
||||||
|
return getRepository().findFirstByVmNameOrderByIdDesc(vmName);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user