first commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.ikon.itassetmanagement;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
import com.ikon.autoconfigure.annotation.EnableIkonSdk;
|
||||
import com.ikon.sdk.config.IkonSdkConfig;
|
||||
|
||||
@EntityScan(basePackages = { "com.ikon.itassetmanagement.entity" })
|
||||
@EnableJpaRepositories(basePackages = { "com.ikon.itassetmanagement.repository" })
|
||||
@EnableIkonSdk(configuration = IkonSdkConfig.class)
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {
|
||||
"com.ikon.itassetmanagement",
|
||||
"com.ikon.sdk"
|
||||
})
|
||||
public class ItAssetManagementApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ItAssetManagementApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ikon.itassetmanagement.config;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ModelMapperConfig {
|
||||
|
||||
@Bean
|
||||
public ModelMapper modelMapper() {
|
||||
return new ModelMapper();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.ikon.itassetmanagement.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
|
||||
import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
|
||||
import com.ikon.webservice.security.IkonJwtTokenConverter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableMethodSecurity
|
||||
public class SecurityConfig {
|
||||
|
||||
private Converter<Jwt, JwtAuthenticationToken> ikonJwtTokenConverter = new IkonJwtTokenConverter(
|
||||
new JwtGrantedAuthoritiesConverter());
|
||||
|
||||
@Bean
|
||||
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http
|
||||
// ENABLE CORS - This is critical for cross-origin requests
|
||||
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
.httpBasic(AbstractHttpConfigurer::disable)
|
||||
.authorizeHttpRequests((authorize) -> {
|
||||
authorize
|
||||
// 1. Allow all actuator health endpoints first
|
||||
.requestMatchers("/actuator/health", "/actuator/health/**").permitAll()
|
||||
// 2. Allow hardware-types endpoints without auth (for development/testing)
|
||||
// .requestMatchers("/api/hardware-types", "/api/hardware-types/**").permitAll()
|
||||
// // 3. Allow hardware-locations endpoints without auth (for development/testing)
|
||||
// .requestMatchers("/api/hardware-locations", "/api/hardware-locations/**").permitAll()
|
||||
// // 4. Allow hardware-assets endpoints without auth (for development/testing)
|
||||
// .requestMatchers("/api/hardware-assets", "/api/hardware-assets/**").permitAll()
|
||||
// 5. Authenticate all other requests
|
||||
.anyRequest().authenticated();
|
||||
})
|
||||
.oauth2ResourceServer((oauth2) -> {
|
||||
oauth2.jwt((jwt) -> jwt.jwtAuthenticationConverter(ikonJwtTokenConverter));
|
||||
});
|
||||
|
||||
return http.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsConfigurationSource corsConfigurationSource() {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
|
||||
// Allow requests from localhost (for development) and your production domain
|
||||
configuration.setAllowedOriginPatterns(
|
||||
Arrays.asList(
|
||||
"http://localhost:*", // Local development
|
||||
"https://*.keross.com", // Production domain
|
||||
"http://103.121.157.108", // Your server IP
|
||||
"http://103.121.157.108:*" // Your server IP with any port
|
||||
));
|
||||
|
||||
// Allow all standard HTTP methods
|
||||
configuration.setAllowedMethods(
|
||||
Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"));
|
||||
|
||||
// Allow all headers (or specify specific ones)
|
||||
configuration.setAllowedHeaders(Arrays.asList("*"));
|
||||
|
||||
// Allow credentials (cookies, authorization headers, etc.)
|
||||
configuration.setAllowCredentials(true);
|
||||
|
||||
// Cache preflight response for 1 hour
|
||||
configuration.setMaxAge(3600L);
|
||||
|
||||
// Expose headers that the client can access
|
||||
configuration.setExposedHeaders(
|
||||
Arrays.asList(
|
||||
"Authorization",
|
||||
"Content-Type",
|
||||
"Content-Disposition",
|
||||
"X-Total-Count" // If you use pagination headers
|
||||
));
|
||||
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", configuration);
|
||||
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.ikon.itassetmanagement.controller;
|
||||
|
||||
import com.ikon.itassetmanagement.dto.request.CreateHardwareAssetRequest;
|
||||
import com.ikon.itassetmanagement.dto.response.HardwareAssetResponse;
|
||||
import com.ikon.itassetmanagement.entity.HardwareLocation;
|
||||
import com.ikon.itassetmanagement.entity.HardwareType;
|
||||
import com.ikon.itassetmanagement.mapper.HardwareAssetMapper;
|
||||
import com.ikon.itassetmanagement.repository.HardwareAsset;
|
||||
import com.ikon.itassetmanagement.repository.HardwareAssetRepository;
|
||||
import com.ikon.itassetmanagement.repository.HardwareLocationRepository;
|
||||
import com.ikon.itassetmanagement.repository.HardwareTypeRepository;
|
||||
|
||||
import com.ikon.itassetmanagement.service.HardwareAssetService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/hardware-assets")
|
||||
public class HardwareAssetController {
|
||||
|
||||
@Autowired
|
||||
private HardwareAssetService service;
|
||||
|
||||
@Autowired
|
||||
private HardwareTypeRepository typeRepository;
|
||||
|
||||
@Autowired
|
||||
private HardwareLocationRepository locationRepository;
|
||||
|
||||
@Autowired
|
||||
private HardwareAssetRepository assetRepository;
|
||||
|
||||
// CREATE API
|
||||
@PostMapping
|
||||
public HardwareAssetResponse create(
|
||||
@RequestBody CreateHardwareAssetRequest request
|
||||
) {
|
||||
|
||||
Long hardwareTypeId = Long.valueOf(request.getHardwareTypeId());
|
||||
Long locationId = Long.valueOf(request.getLocationId());
|
||||
HardwareType type =
|
||||
typeRepository.findById(
|
||||
hardwareTypeId
|
||||
).orElseThrow();
|
||||
|
||||
HardwareLocation location = locationRepository.findById(locationId).orElseThrow();
|
||||
|
||||
|
||||
HardwareAsset asset = new HardwareAsset();
|
||||
|
||||
asset.setAssetTag(request.getAssetTag());
|
||||
|
||||
asset.setName(request.getName());
|
||||
|
||||
asset.setManufacturer(
|
||||
request.getManufacturer()
|
||||
);
|
||||
|
||||
asset.setModel(request.getModel());
|
||||
|
||||
asset.setSerialNumber(
|
||||
request.getSerialNumber()
|
||||
);
|
||||
|
||||
asset.setHardwareType(type);
|
||||
|
||||
asset.setLocation(location);
|
||||
|
||||
HardwareAsset saved =
|
||||
service.save(asset);
|
||||
|
||||
return HardwareAssetMapper
|
||||
.mapToResponse(saved);
|
||||
}
|
||||
|
||||
// GET ALL API
|
||||
@GetMapping
|
||||
public List<HardwareAssetResponse> getAll() {
|
||||
|
||||
return service.getAll()
|
||||
.stream()
|
||||
.map(HardwareAssetMapper::mapToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@DeleteMapping("/{id}")
|
||||
public String delete(
|
||||
@PathVariable Long id
|
||||
) {
|
||||
|
||||
service.delete(id);
|
||||
|
||||
return "Deleted Successfully";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.ikon.itassetmanagement.controller;
|
||||
|
||||
|
||||
import com.ikon.itassetmanagement.dto.request.CreateHardwareLocationRequest;
|
||||
import com.ikon.itassetmanagement.dto.response.HardwareLocationResponse;
|
||||
import com.ikon.itassetmanagement.entity.HardwareLocation;
|
||||
import com.ikon.itassetmanagement.mapper.HardwareLocationMapper;
|
||||
import com.ikon.itassetmanagement.service.HardwareLocationService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/hardware-locations")
|
||||
public class HardwareLocationController {
|
||||
|
||||
@Autowired
|
||||
private HardwareLocationService service;
|
||||
|
||||
// CREATE API
|
||||
@PostMapping
|
||||
public HardwareLocationResponse createLocation(
|
||||
@RequestBody CreateHardwareLocationRequest request
|
||||
) {
|
||||
|
||||
HardwareLocation location =
|
||||
new HardwareLocation();
|
||||
|
||||
location.setLocationName(
|
||||
request.getLocation()
|
||||
);
|
||||
|
||||
location.setAddress(
|
||||
request.getAddress()
|
||||
);
|
||||
|
||||
HardwareLocation saved =
|
||||
service.create(location);
|
||||
|
||||
return HardwareLocationMapper
|
||||
.mapToResponse(saved);
|
||||
}
|
||||
|
||||
// GET ALL API
|
||||
@GetMapping
|
||||
public List<HardwareLocationResponse> getAll() {
|
||||
|
||||
return service.getAll()
|
||||
.stream()
|
||||
.map(HardwareLocationMapper::mapToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// DELETE API
|
||||
@DeleteMapping("/{id}")
|
||||
public String delete(
|
||||
@PathVariable Long id
|
||||
) {
|
||||
|
||||
service.delete(id);
|
||||
|
||||
return "Location Deleted Successfully";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.ikon.itassetmanagement.controller;
|
||||
import com.ikon.itassetmanagement.dto.request.CreateHardwareTypeRequest;
|
||||
import com.ikon.itassetmanagement.dto.response.HardwareTypeResponse;
|
||||
import com.ikon.itassetmanagement.entity.HardwareType;
|
||||
import com.ikon.itassetmanagement.mapper.HardwareTypeMapper;
|
||||
import com.ikon.itassetmanagement.service.HardwareTypeService;
|
||||
import com.ikon.itassetmanagement.repository.HardwareTypeRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/hardware-types")
|
||||
public class HardwareTypeController {
|
||||
|
||||
@Autowired
|
||||
private HardwareTypeService service;
|
||||
|
||||
|
||||
@Autowired
|
||||
private HardwareTypeRepository repository;
|
||||
|
||||
// CREATE API
|
||||
@PostMapping
|
||||
public HardwareType createHardwareType( @RequestBody HardwareType request) {
|
||||
return service.create(request);
|
||||
}
|
||||
|
||||
// GET ALL API
|
||||
@GetMapping
|
||||
public List<HardwareType> getAll() {
|
||||
return service.getAll();
|
||||
}
|
||||
|
||||
// UPDATE API
|
||||
@PutMapping("/{id}")
|
||||
public HardwareTypeResponse updateHardwareType(
|
||||
@PathVariable Long id,
|
||||
@RequestBody CreateHardwareTypeRequest request
|
||||
) {
|
||||
|
||||
HardwareType hardwareType = new HardwareType();
|
||||
hardwareType.setId(id);
|
||||
hardwareType.setHardwareType(request.getHardwareType());
|
||||
hardwareType.setAbbreviation(request.getAbbreviation());
|
||||
|
||||
HardwareType updated = service.update(hardwareType);
|
||||
|
||||
return HardwareTypeMapper.mapToResponse(updated);
|
||||
}
|
||||
|
||||
// DELETE API
|
||||
@DeleteMapping("/{id}")
|
||||
public String delete(
|
||||
@PathVariable Long id
|
||||
) {
|
||||
|
||||
service.delete(id);
|
||||
|
||||
return "Deleted Successfully";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.ikon.itassetmanagement.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.ikon.itassetmanagement.api.SoftwareConfigurationApi;
|
||||
import com.ikon.itassetmanagement.dto.request.CreateSoftwareConfig;
|
||||
import com.ikon.itassetmanagement.dto.response.SoftwareConfigurationResponse;
|
||||
import com.ikon.itassetmanagement.service.SoftwareConfigService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class SoftwareConfigurationController implements SoftwareConfigurationApi {
|
||||
|
||||
private final SoftwareConfigService softwareConfigService;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<SoftwareConfigurationResponse> createSoftwareConfiguration(String accessToken,
|
||||
@Valid CreateSoftwareConfig request) {
|
||||
SoftwareConfigurationResponse response = softwareConfigService.createSoftwareConfiguration(request);
|
||||
return ResponseEntity.ok(response);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<SoftwareConfigurationResponse> getSoftwareConfigurationById(String accessToken, Long id) {
|
||||
SoftwareConfigurationResponse response = softwareConfigService.getSoftwareConfigurationById(id);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<SoftwareConfigurationResponse>> getAllSoftwareConfigurations(String accessToken) {
|
||||
List<SoftwareConfigurationResponse> response = softwareConfigService.getAllSoftwareConfigurations();
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<SoftwareConfigurationResponse> updateSoftwareConfiguration(String accessToken, Long id,
|
||||
@Valid CreateSoftwareConfig request) {
|
||||
SoftwareConfigurationResponse response = softwareConfigService.updateSoftwareConfiguration(id, request);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> deleteSoftwareConfiguration(String accessToken, Long id) {
|
||||
softwareConfigService.deleteSoftwareConfiguration(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.ikon.itassetmanagement.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.ikon.itassetmanagement.api.SoftwareApi;
|
||||
|
||||
import com.ikon.itassetmanagement.dto.request.SoftwareRequest;
|
||||
|
||||
import com.ikon.itassetmanagement.dto.response.SoftwareResponse;
|
||||
import com.ikon.itassetmanagement.service.SoftwareService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class SoftwareController implements SoftwareApi {
|
||||
private final SoftwareService softwareService;
|
||||
@Override
|
||||
public ResponseEntity<SoftwareResponse> createSoftware(String accessToken,
|
||||
@Valid SoftwareRequest request) {
|
||||
SoftwareResponse response = softwareService.createSoftware(request);
|
||||
return ResponseEntity.ok(response);
|
||||
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<SoftwareResponse> getSoftwareById(String accessToken, Long id) {
|
||||
// Implementation for getting software by ID
|
||||
SoftwareResponse response = softwareService.getSoftwareById(id);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<List<SoftwareResponse>> getAllSoftware(String accessToken) {
|
||||
// Implementation for getting all software
|
||||
List<SoftwareResponse> response = softwareService.getAllSoftware();
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Void> deleteSoftware(String accessToken, Long id) {
|
||||
// Implementation for deleting software
|
||||
softwareService.deleteSoftware(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.ikon.itassetmanagement.controller;
|
||||
|
||||
import com.ikon.itassetmanagement.api.TaskApi;
|
||||
import com.ikon.itassetmanagement.dto.request.TaskRequest;
|
||||
import com.ikon.itassetmanagement.dto.response.TaskResponse;
|
||||
import com.ikon.itassetmanagement.enums.TaskPriority;
|
||||
import com.ikon.itassetmanagement.enums.TaskStatus;
|
||||
import com.ikon.itassetmanagement.service.TaskService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class TaskController implements TaskApi {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<TaskResponse> createTask(String accessToken, TaskRequest request) {
|
||||
TaskResponse response = taskService.createTask(request);
|
||||
return new ResponseEntity<>(response, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<TaskResponse> getTaskById(String accessToken, Long id) {
|
||||
TaskResponse response = taskService.getTaskById(id);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<TaskResponse>> getAllTasks(String accessToken, TaskStatus status, TaskPriority priority,
|
||||
String search) {
|
||||
List<TaskResponse> tasks = taskService.getAllTasksWithFilters(status, priority, search);
|
||||
|
||||
return ResponseEntity.ok(tasks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Page<TaskResponse>> getTasksPaginated(String accessToken, Pageable pageable,
|
||||
TaskStatus status, TaskPriority priority,
|
||||
String search) {
|
||||
Page<TaskResponse> taskPage = taskService.getTasksPaginated(pageable, status, priority, search);
|
||||
return ResponseEntity.ok(taskPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<TaskResponse> updateTask(String accessToken, Long id, TaskRequest request) {
|
||||
TaskResponse response = taskService.updateTask(id, request);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> deleteTask(String accessToken, Long id) {
|
||||
taskService.deleteTask(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.ikon.itassetmanagement.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "hardware_asset")
|
||||
public class HardwareAsset {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String assetTag;
|
||||
|
||||
private String name;
|
||||
|
||||
private String manufacturer;
|
||||
|
||||
private String model;
|
||||
|
||||
private String serialNumber;
|
||||
|
||||
// MANY ASSETS -> ONE TYPE
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "hardware_type_id")
|
||||
private HardwareType hardwareType;
|
||||
|
||||
// MANY ASSETS -> ONE LOCATION
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "location_id" )
|
||||
private HardwareLocation location;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.ikon.itassetmanagement.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "hardware_location")
|
||||
public class HardwareLocation {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String locationName;
|
||||
|
||||
private String address;
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getLocationName() {
|
||||
return locationName;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setLocationName(String locationName) {
|
||||
this.locationName = locationName;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.ikon.itassetmanagement.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "hardware_type")
|
||||
public class HardwareType {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String hardwareType;
|
||||
|
||||
@Column(nullable = false, unique = true, length = 8)
|
||||
private String abbreviation;
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getHardwareType() {
|
||||
return hardwareType;
|
||||
}
|
||||
|
||||
public void setHardwareType(String hardwareType) {
|
||||
this.hardwareType = hardwareType;
|
||||
}
|
||||
|
||||
public String getAbbreviation() {
|
||||
return abbreviation;
|
||||
}
|
||||
|
||||
public void setAbbreviation(String abbreviation) {
|
||||
this.abbreviation = abbreviation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ikon.itassetmanagement.entity;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "software")
|
||||
public class Software {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@Column(nullable = false)
|
||||
private String softwareName;
|
||||
private String softwareVendor;
|
||||
@Column(nullable = false)
|
||||
private Long softwareCategoryId;
|
||||
private String softwareVersion;
|
||||
private int totalLicenses;
|
||||
private int costPerLicense;
|
||||
private String webSiteURL;
|
||||
private String invoiceURL;
|
||||
private String logInCredentials;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.ikon.itassetmanagement.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "software_configuration")
|
||||
public class SoftwareConfiguration {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String softwareCategory;
|
||||
|
||||
@Column(nullable = false, unique = true, length = 8)
|
||||
private String softwareAbbreviation;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.ikon.itassetmanagement.entity;
|
||||
|
||||
import com.ikon.itassetmanagement.enums.TaskPriority;
|
||||
import com.ikon.itassetmanagement.enums.TaskStatus;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "tasks")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Task {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false, length = 100)
|
||||
private String title;
|
||||
|
||||
@Column(length = 500)
|
||||
private String description;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(nullable = false)
|
||||
private TaskStatus status = TaskStatus.PENDING;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(nullable = false)
|
||||
private TaskPriority priority = TaskPriority.MEDIUM;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@UpdateTimestamp
|
||||
@Column(nullable = false)
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.ikon.itassetmanagement.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public ResponseEntity<Map<String, Object>> handleRuntimeException(RuntimeException ex) {
|
||||
Map<String, Object> errorResponse = new HashMap<>();
|
||||
errorResponse.put("timestamp", LocalDateTime.now());
|
||||
errorResponse.put("message", ex.getMessage());
|
||||
errorResponse.put("status", HttpStatus.NOT_FOUND.value());
|
||||
|
||||
return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public ResponseEntity<Map<String, Object>> handleValidationExceptions(
|
||||
MethodArgumentNotValidException ex) {
|
||||
Map<String, String> errors = new HashMap<>();
|
||||
ex.getBindingResult().getAllErrors().forEach((error) -> {
|
||||
String fieldName = ((FieldError) error).getField();
|
||||
String errorMessage = error.getDefaultMessage();
|
||||
errors.put(fieldName, errorMessage);
|
||||
});
|
||||
|
||||
Map<String, Object> errorResponse = new HashMap<>();
|
||||
errorResponse.put("timestamp", LocalDateTime.now());
|
||||
errorResponse.put("message", "Validation failed");
|
||||
errorResponse.put("errors", errors);
|
||||
errorResponse.put("status", HttpStatus.BAD_REQUEST.value());
|
||||
|
||||
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<Map<String, Object>> handleGlobalException(Exception ex) {
|
||||
Map<String, Object> errorResponse = new HashMap<>();
|
||||
errorResponse.put("timestamp", LocalDateTime.now());
|
||||
errorResponse.put("message", "An error occurred: " + ex.getMessage());
|
||||
errorResponse.put("status", HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||
|
||||
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.ikon.itassetmanagement.mapper;
|
||||
|
||||
import com.ikon.itassetmanagement.dto.response.HardwareAssetResponse;
|
||||
import com.ikon.itassetmanagement.repository.HardwareAsset;
|
||||
|
||||
public class HardwareAssetMapper {
|
||||
|
||||
public static HardwareAssetResponse mapToResponse(
|
||||
HardwareAsset asset
|
||||
) {
|
||||
|
||||
HardwareAssetResponse response =
|
||||
new HardwareAssetResponse();
|
||||
|
||||
response.setId(asset.getId());
|
||||
|
||||
response.setAssetTag(asset.getAssetTag());
|
||||
|
||||
response.setName(asset.getName());
|
||||
|
||||
response.setManufacturer(
|
||||
asset.getManufacturer()
|
||||
);
|
||||
|
||||
response.setModel(asset.getModel());
|
||||
|
||||
response.setSerialNumber(
|
||||
asset.getSerialNumber()
|
||||
);
|
||||
|
||||
response.setHardwareTypeId(
|
||||
asset.getHardwareType()
|
||||
.getId()
|
||||
);
|
||||
|
||||
response.setLocationId(
|
||||
asset.getLocation()
|
||||
.getId()
|
||||
);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.ikon.itassetmanagement.mapper;
|
||||
|
||||
|
||||
import com.ikon.itassetmanagement.dto.response.HardwareLocationResponse;
|
||||
import com.ikon.itassetmanagement.entity.HardwareLocation;
|
||||
|
||||
public class HardwareLocationMapper {
|
||||
|
||||
public static HardwareLocationResponse mapToResponse(
|
||||
HardwareLocation location
|
||||
) {
|
||||
|
||||
HardwareLocationResponse response =
|
||||
new HardwareLocationResponse();
|
||||
|
||||
response.setId(location.getId());
|
||||
response.setLocationName(
|
||||
location.getLocationName()
|
||||
);
|
||||
response.setAddress(location.getAddress());
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ikon.itassetmanagement.mapper;
|
||||
|
||||
import com.ikon.itassetmanagement.dto.response.HardwareTypeResponse;
|
||||
import com.ikon.itassetmanagement.entity.HardwareType;
|
||||
|
||||
public class HardwareTypeMapper {
|
||||
|
||||
public static HardwareTypeResponse mapToResponse(
|
||||
HardwareType hardwareType
|
||||
) {
|
||||
|
||||
HardwareTypeResponse response =
|
||||
new HardwareTypeResponse();
|
||||
|
||||
response.setId(hardwareType.getId());
|
||||
response.setHardwareType(
|
||||
hardwareType.getHardwareType()
|
||||
);
|
||||
response.setAbbreviation(
|
||||
hardwareType.getAbbreviation()
|
||||
);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.ikon.itassetmanagement.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.ikon.itassetmanagement.entity.HardwareAsset;
|
||||
|
||||
public interface HardwareAssetRepository
|
||||
extends JpaRepository<HardwareAsset, Long> {
|
||||
|
||||
long countByHardwareTypeId(Long hardwareTypeId);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.ikon.itassetmanagement.repository;
|
||||
|
||||
import com.ikon.itassetmanagement.entity.HardwareLocation;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface HardwareLocationRepository
|
||||
extends JpaRepository<HardwareLocation, Long> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.ikon.itassetmanagement.repository;
|
||||
|
||||
import com.ikon.itassetmanagement.entity.HardwareType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface HardwareTypeRepository
|
||||
extends JpaRepository<HardwareType, Long> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ikon.itassetmanagement.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.ikon.itassetmanagement.entity.SoftwareConfiguration;
|
||||
|
||||
public interface SoftwareCategoryRepository
|
||||
extends JpaRepository<SoftwareConfiguration, Long> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ikon.itassetmanagement.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.ikon.itassetmanagement.entity.Software;
|
||||
|
||||
public interface SoftwareRepository
|
||||
extends JpaRepository<Software, Long> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.ikon.itassetmanagement.repository;
|
||||
|
||||
import com.ikon.itassetmanagement.entity.Task;
|
||||
import com.ikon.itassetmanagement.enums.TaskPriority;
|
||||
import com.ikon.itassetmanagement.enums.TaskStatus;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface TaskRepository extends JpaRepository<Task, Long> {
|
||||
|
||||
// Single query method for all filters (non-paginated)
|
||||
@Query("SELECT t FROM Task t WHERE " +
|
||||
"(:status IS NULL OR t.status = :status) AND " +
|
||||
"(:priority IS NULL OR t.priority = :priority) AND " +
|
||||
"(:search IS NULL OR :search = '' OR LOWER(t.title) LIKE LOWER(CONCAT('%', :search, '%')))")
|
||||
List<Task> findAllWithFilters(
|
||||
@Param("status") TaskStatus status,
|
||||
@Param("priority") TaskPriority priority,
|
||||
@Param("search") String search
|
||||
);
|
||||
|
||||
// Single query method for all filters (paginated)
|
||||
@Query("SELECT t FROM Task t WHERE " +
|
||||
"(:status IS NULL OR t.status = :status) AND " +
|
||||
"(:priority IS NULL OR t.priority = :priority) AND " +
|
||||
"(:search IS NULL OR :search = '' OR LOWER(t.title) LIKE LOWER(CONCAT('%', :search, '%')))")
|
||||
Page<Task> findAllWithFiltersPaginated(
|
||||
@Param("status") TaskStatus status,
|
||||
@Param("priority") TaskPriority priority,
|
||||
@Param("search") String search,
|
||||
Pageable pageable
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ikon.itassetmanagement.service;
|
||||
|
||||
import com.ikon.itassetmanagement.repository.HardwareAssetRepository;
|
||||
import com.ikon.itassetmanagement.entity.HardwareAsset;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class HardwareAssetService {
|
||||
@Autowired
|
||||
private HardwareAssetRepository repository;
|
||||
|
||||
public HardwareAsset save(HardwareAsset asset) {
|
||||
return repository.save(asset);
|
||||
}
|
||||
|
||||
public List<HardwareAsset> getAll() {
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
public void delete(Long id) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ikon.itassetmanagement.service;
|
||||
|
||||
import com.ikon.itassetmanagement.entity.HardwareLocation;
|
||||
import com.ikon.itassetmanagement.repository.HardwareLocationRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class HardwareLocationService {
|
||||
|
||||
@Autowired
|
||||
private HardwareLocationRepository repository;
|
||||
|
||||
// CREATE
|
||||
public HardwareLocation create(
|
||||
HardwareLocation location
|
||||
) {
|
||||
|
||||
return repository.save(location);
|
||||
}
|
||||
|
||||
// GET ALL
|
||||
public List<HardwareLocation> getAll() {
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
// DELETE
|
||||
public void delete(Long id) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.ikon.itassetmanagement.service;
|
||||
|
||||
import com.ikon.itassetmanagement.entity.HardwareType;
|
||||
import com.ikon.itassetmanagement.repository.HardwareTypeRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class HardwareTypeService {
|
||||
|
||||
@Autowired
|
||||
private HardwareTypeRepository repository;
|
||||
|
||||
// CREATE
|
||||
public HardwareType create(HardwareType hardwareType) {
|
||||
|
||||
String abbreviation = hardwareType.getAbbreviation();
|
||||
hardwareType.setAbbreviation(abbreviation.toUpperCase());
|
||||
|
||||
return repository.save(hardwareType);
|
||||
}
|
||||
|
||||
// GET ALL
|
||||
public List<HardwareType> getAll() {
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
// UPDATE
|
||||
public HardwareType update(HardwareType hardwareType) {
|
||||
|
||||
hardwareType.setAbbreviation(
|
||||
hardwareType.getAbbreviation().toUpperCase()
|
||||
);
|
||||
|
||||
return repository.save(hardwareType);
|
||||
}
|
||||
|
||||
// DELETE
|
||||
public void delete(Long id) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.ikon.itassetmanagement.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ikon.itassetmanagement.dto.request.CreateSoftwareConfig;
|
||||
import com.ikon.itassetmanagement.dto.response.SoftwareConfigurationResponse;
|
||||
import com.ikon.itassetmanagement.entity.SoftwareConfiguration;
|
||||
import com.ikon.itassetmanagement.repository.SoftwareCategoryRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SoftwareConfigService {
|
||||
private final SoftwareCategoryRepository softwareCategoryRepository;
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
public SoftwareConfigurationResponse createSoftwareConfiguration(CreateSoftwareConfig request) {
|
||||
SoftwareConfiguration softwareConfig = modelMapper.map(request, SoftwareConfiguration.class);
|
||||
SoftwareConfiguration savedConfig = softwareCategoryRepository.save(softwareConfig);
|
||||
return modelMapper.map(savedConfig, SoftwareConfigurationResponse.class);
|
||||
}
|
||||
|
||||
public SoftwareConfigurationResponse getSoftwareConfigurationById(Long id) {
|
||||
SoftwareConfiguration softwareConfig = softwareCategoryRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Software configuration not found with id: " + id));
|
||||
return modelMapper.map(softwareConfig, SoftwareConfigurationResponse.class);
|
||||
}
|
||||
public SoftwareConfigurationResponse updateSoftwareConfiguration(Long id, CreateSoftwareConfig request) {
|
||||
SoftwareConfiguration existingConfig = softwareCategoryRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Software configuration not found with id: " + id));
|
||||
modelMapper.map(request, existingConfig);
|
||||
SoftwareConfiguration updatedConfig = softwareCategoryRepository.save(existingConfig);
|
||||
return modelMapper.map(updatedConfig, SoftwareConfigurationResponse.class);
|
||||
}
|
||||
public void deleteSoftwareConfiguration(Long id) {
|
||||
if (!softwareCategoryRepository.existsById(id)) {
|
||||
throw new RuntimeException("Software configuration not found with id: " + id);
|
||||
}
|
||||
softwareCategoryRepository.deleteById(id);
|
||||
}
|
||||
public List<SoftwareConfigurationResponse> getAllSoftwareConfigurations() {
|
||||
return softwareCategoryRepository.findAll().stream()
|
||||
.map(config -> modelMapper.map(config, SoftwareConfigurationResponse.class))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.ikon.itassetmanagement.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ikon.itassetmanagement.dto.request.SoftwareRequest;
|
||||
|
||||
import com.ikon.itassetmanagement.dto.response.SoftwareResponse;
|
||||
import com.ikon.itassetmanagement.entity.Software;
|
||||
|
||||
import com.ikon.itassetmanagement.repository.SoftwareRepository;
|
||||
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SoftwareService{
|
||||
private final SoftwareRepository softwareRepository;
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
|
||||
public SoftwareResponse createSoftware(SoftwareRequest request) {
|
||||
Software software = new Software();
|
||||
|
||||
software.setSoftwareName(request.getSoftwareName());
|
||||
software.setSoftwareVendor(request.getSoftwareVendor());
|
||||
software.setSoftwareCategoryId(request.getSoftwareCategoryId());
|
||||
software.setSoftwareVersion(request.getSoftwareVersion());
|
||||
software.setTotalLicenses(request.getTotalLicenses());
|
||||
software.setCostPerLicense(request.getCostPerLicense());
|
||||
software.setWebSiteURL(request.getWebSiteURL());
|
||||
software.setInvoiceURL(request.getInvoiceURL());
|
||||
software.setLogInCredentials(request.getLogInCredentials());
|
||||
System.out.println("ID before save = " + software.getId());
|
||||
Software saved = softwareRepository.save(software);
|
||||
return modelMapper.map(saved, SoftwareResponse.class);
|
||||
}
|
||||
public SoftwareResponse getSoftwareById(Long id) {
|
||||
Software software= softwareRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Software not found with id: " + id));
|
||||
return modelMapper.map(software, SoftwareResponse.class);
|
||||
}
|
||||
|
||||
public void deleteSoftware(Long id) {
|
||||
if (!softwareRepository.existsById(id)) {
|
||||
throw new RuntimeException("Software not found with id: " + id);
|
||||
}
|
||||
softwareRepository.deleteById(id);
|
||||
}
|
||||
public List<SoftwareResponse> getAllSoftware() {
|
||||
return softwareRepository.findAll().stream()
|
||||
.map(software -> modelMapper.map(software, SoftwareResponse.class))
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.ikon.itassetmanagement.service;
|
||||
|
||||
import com.ikon.itassetmanagement.dto.request.TaskRequest;
|
||||
import com.ikon.itassetmanagement.dto.response.TaskResponse;
|
||||
import com.ikon.itassetmanagement.entity.Task;
|
||||
import com.ikon.itassetmanagement.enums.TaskPriority;
|
||||
import com.ikon.itassetmanagement.enums.TaskStatus;
|
||||
import com.ikon.itassetmanagement.repository.TaskRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TaskService {
|
||||
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
@Transactional
|
||||
public TaskResponse createTask(TaskRequest request) {
|
||||
Task task = modelMapper.map(request, Task.class);
|
||||
|
||||
// Set default values if not provided
|
||||
if (task.getStatus() == null) {
|
||||
task.setStatus(TaskStatus.PENDING);
|
||||
}
|
||||
if (task.getPriority() == null) {
|
||||
task.setPriority(TaskPriority.MEDIUM);
|
||||
}
|
||||
|
||||
Task savedTask = taskRepository.save(task);
|
||||
return modelMapper.map(savedTask, TaskResponse.class);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public TaskResponse getTaskById(Long id) {
|
||||
Task task = taskRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Task not found with id: " + id));
|
||||
return modelMapper.map(task, TaskResponse.class);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<TaskResponse> getAllTasksWithFilters(TaskStatus status, TaskPriority priority, String search) {
|
||||
return taskRepository.findAllWithFilters(status, priority, search).stream()
|
||||
.map(task -> modelMapper.map(task, TaskResponse.class))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Page<TaskResponse> getTasksPaginated(Pageable pageable, TaskStatus status,
|
||||
TaskPriority priority, String search) {
|
||||
Page<Task> taskPage = taskRepository.findAllWithFiltersPaginated(status, priority, search, pageable);
|
||||
return taskPage.map(task -> modelMapper.map(task, TaskResponse.class));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public TaskResponse updateTask(Long id, TaskRequest request) {
|
||||
Task existingTask = taskRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Task not found with id: " + id));
|
||||
|
||||
// Update fields
|
||||
existingTask.setTitle(request.getTitle());
|
||||
existingTask.setDescription(request.getDescription());
|
||||
|
||||
if (request.getStatus() != null) {
|
||||
existingTask.setStatus(request.getStatus());
|
||||
}
|
||||
if (request.getPriority() != null) {
|
||||
existingTask.setPriority(request.getPriority());
|
||||
}
|
||||
|
||||
Task updatedTask = taskRepository.save(existingTask);
|
||||
return modelMapper.map(updatedTask, TaskResponse.class);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteTask(Long id) {
|
||||
if (!taskRepository.existsById(id)) {
|
||||
throw new RuntimeException("Task not found with id: " + id);
|
||||
}
|
||||
taskRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,149 @@
|
||||
spring:
|
||||
application:
|
||||
name: it-asset-management
|
||||
|
||||
datasource:
|
||||
url: jdbc:mysql://192.168.3.144:3306/itassetmanagement?createDatabaseIfNotExist=true
|
||||
username: root
|
||||
password: rootpassword123
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
hikari:
|
||||
connectionTimeout: 20000
|
||||
maximumPoolSize: 20
|
||||
jpa:
|
||||
database-platform: org.hibernate.dialect.MySQL8Dialect
|
||||
hibernate:
|
||||
ddl-auto: update # Options: none, validate, update, create, create-drop
|
||||
show-sql: true
|
||||
defer-datasource-initialization: false
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
|
||||
# If you are using process, uncomment below
|
||||
# sql:
|
||||
# init:
|
||||
# schema-locations:
|
||||
# - classpath:activiti.engine.schema.sql
|
||||
# mode: always
|
||||
|
||||
security:
|
||||
oauth2:
|
||||
resourceserver:
|
||||
jwt:
|
||||
issuer-uri: https://ikoncloud-dev.keross.com/ikon-api/platform
|
||||
|
||||
# If you use any one of the below data sources, uncomment data and the respective section.
|
||||
# data:
|
||||
|
||||
# If you are using redis, uncomment below
|
||||
# redis:
|
||||
# host: localhost
|
||||
# port: 6379
|
||||
# password: 7410
|
||||
# database: 0
|
||||
# lettuce:
|
||||
# pool:
|
||||
# max-active: 10 # Maximum number of connections
|
||||
# max-idle: 8 # Maximum idle connections
|
||||
# min-idle: 2 # Minimum idle connections
|
||||
# max-wait: 5s # Max wait time for a connection
|
||||
|
||||
# If you are using mongodb, uncomment below
|
||||
# mongodb:
|
||||
# host: localhost
|
||||
# port: 27017
|
||||
# username: system
|
||||
# password: admin
|
||||
# authentication-database: admin
|
||||
# mongodb:
|
||||
# client:
|
||||
# settings:
|
||||
# connection-pool:
|
||||
# max-size: 500 # Maximum connections in the pool
|
||||
# min-size: 10 # Minimum idle connections
|
||||
# max-connection-idle-time: 10s # Time a connection can be idle before being closed
|
||||
# max-wait-time: 5s
|
||||
|
||||
# If you are using kafka, uncomment below
|
||||
# kafka:
|
||||
# bootstrap-servers: localhost:9092
|
||||
# properties:
|
||||
# schema:
|
||||
# registry:
|
||||
# url: http://localhost:8081
|
||||
# specific:
|
||||
# avro:
|
||||
# reader: true
|
||||
# producer:
|
||||
# key-serializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
# value-serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
|
||||
# consumer:
|
||||
# key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
||||
# value-deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
|
||||
# group-id: ${spring.application.name}-consumer-group
|
||||
# auto-offset-reset: earliest
|
||||
|
||||
ikon:
|
||||
user:
|
||||
agent: "IKON App Server"
|
||||
time-zone: "Asia/Kolkata"
|
||||
platform:
|
||||
rest:
|
||||
url: https://ikoncloud-dev.keross.com/ikon-api/platform
|
||||
logger:
|
||||
enabled: false # set true when deployed in dev/uat/prod otherwise set to false if running in local/devtools environment.
|
||||
app:
|
||||
softwareId: "00065ac0-32ea-4978-8ab1-5402f041413c"
|
||||
softwareVersion: 1
|
||||
softwareName: "IT Asset Management"
|
||||
softwareRepositoryName: "it-asset-management"
|
||||
accessmanagement:
|
||||
init:
|
||||
file: ../../bpmn/project.json
|
||||
|
||||
# If you are using process, uncomment below
|
||||
# processengine:
|
||||
# databaseSchemaUpdate: false # possible values: "true", "false", "create-drop"
|
||||
# bpmn:
|
||||
# enabled: true
|
||||
# path: "../../bpmn"
|
||||
# job:
|
||||
# max-pool-size: 100
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.ikon: DEBUG
|
||||
file:
|
||||
name: "../logs/${spring.application.name}-app.log"
|
||||
|
||||
server:
|
||||
address: 0.0.0.0
|
||||
port: 8070
|
||||
|
||||
eureka:
|
||||
instance:
|
||||
ip-address: ${server.address}
|
||||
preferIpAddress: true
|
||||
instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
|
||||
client:
|
||||
register-with-eureka: false
|
||||
fetch-registry: false
|
||||
service-url:
|
||||
default-zone: http://localhost:8761/eureka
|
||||
|
||||
management:
|
||||
endpoint:
|
||||
health:
|
||||
probes:
|
||||
enabled: true
|
||||
show-details: always
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health
|
||||
health:
|
||||
livenessState:
|
||||
enabled: true
|
||||
readinessState:
|
||||
enabled: true
|
||||
@@ -0,0 +1,155 @@
|
||||
spring:
|
||||
application:
|
||||
name: {{repo_name}}
|
||||
|
||||
datasource:
|
||||
url: jdbc:mysql://mysql-haproxy.database.svc.cluster.local:3306/{{db_name repo_name}}?createDatabaseIfNotExist=true
|
||||
username: system
|
||||
password: admin
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
hikari:
|
||||
connectionTimeout: 20000
|
||||
maximumPoolSize: 20
|
||||
jpa:
|
||||
database-platform: org.hibernate.dialect.MySQL8Dialect
|
||||
hibernate:
|
||||
ddl-auto: update # Options: none, validate, update, create, create-drop
|
||||
show-sql: true
|
||||
defer-datasource-initialization: false
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
|
||||
# If you are using process, uncomment below
|
||||
# sql:
|
||||
# init:
|
||||
# schema-locations:
|
||||
# - classpath:activiti.engine.schema.sql
|
||||
# mode: always
|
||||
|
||||
security:
|
||||
oauth2:
|
||||
resourceserver:
|
||||
jwt:
|
||||
issuer-uri: https://holocron.keross.com/api/platform
|
||||
|
||||
# If you use any one of the below data sources, uncomment data and the respective section.
|
||||
#data:
|
||||
# If you are using redis, uncomment below
|
||||
# redis:
|
||||
# host: redis.database.svc.cluster.local
|
||||
# port: 6379
|
||||
# password: ducs8WZf7lJnsHm6
|
||||
# database: 0
|
||||
# lettuce:
|
||||
# pool:
|
||||
# max-active: 10 # Maximum number of connections
|
||||
# max-idle: 8 # Maximum idle connections
|
||||
# min-idle: 2 # Minimum idle connections
|
||||
# max-wait: 5s # Max wait time for a connection
|
||||
|
||||
# If you are using mongodb, uncomment below
|
||||
# mongodb:
|
||||
# host: mongo.database.svc.cluster.loca
|
||||
# port: 27017
|
||||
# username: admin
|
||||
# password: admin
|
||||
# authentication-database: admin
|
||||
# mongodb:
|
||||
# client:
|
||||
# settings:
|
||||
# connection-pool:
|
||||
# max-size: 500 # Maximum connections in the pool
|
||||
# min-size: 10 # Minimum idle connections
|
||||
# max-connection-idle-time: 10s # Time a connection can be idle before being closed
|
||||
# max-wait-time: 5s
|
||||
|
||||
# If you are using kafka, uncomment below
|
||||
# kafka:
|
||||
# bootstrap-servers: kafka.kafka.svc.cluster.local:9092
|
||||
# properties:
|
||||
# schema:
|
||||
# registry:
|
||||
# url: http://schemaregistry.kafka.svc.cluster.local:8081
|
||||
# specific:
|
||||
# avro:
|
||||
# reader: true
|
||||
# producer:
|
||||
# key-serializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
# value-serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
|
||||
# consumer:
|
||||
# key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
||||
# value-deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
|
||||
# group-id: ${spring.application.name}-consumer-group
|
||||
# auto-offset-reset: earliest
|
||||
|
||||
|
||||
|
||||
ikon:
|
||||
user:
|
||||
agent: "IKON App Server"
|
||||
time-zone: "Asia/Kolkata"
|
||||
platform:
|
||||
rest:
|
||||
url: http://ikon-api-gateway.ikon-platform.svc.cluster.local:8080/api
|
||||
logger:
|
||||
enabled: false # set true when deployed in dev/uat/prod otherwise set to false if running in local/devtools environment.
|
||||
app:
|
||||
softwareId: "{{software_id}}"
|
||||
softwareVersion: {{version}}
|
||||
softwareName: "{{app_name}}"
|
||||
softwareRepositoryName: "{{repo_name}}"
|
||||
|
||||
accessmanagement:
|
||||
init:
|
||||
file: ./bpmn/project.json
|
||||
|
||||
# If you are using process, uncomment below
|
||||
# processengine:
|
||||
# databaseSchemaUpdate: false # possible values: "true", "false", "create-drop"
|
||||
# bpmn:
|
||||
# enabled: true
|
||||
# path: ./bpmn
|
||||
# job:
|
||||
# max-pool-size: 100
|
||||
|
||||
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.ikon: DEBUG
|
||||
file:
|
||||
name: "../logs/${spring.application.name}-app.log"
|
||||
|
||||
server:
|
||||
address: ${HOSTNAME}
|
||||
port: 8070
|
||||
|
||||
eureka:
|
||||
instance:
|
||||
hostname: ${HOSTNAME}
|
||||
ipAddress: ${{{upper_snake_case repo_name}}_BACKEND_SERVICE_SERVICE_HOST}
|
||||
preferIpAddress: true
|
||||
instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
|
||||
client:
|
||||
registerWithEureka: true
|
||||
fetchRegistry: true
|
||||
serviceUrl:
|
||||
defaultZone: http://ikon-discovery-service.ikon-platform.svc.cluster.local:8761/eureka
|
||||
|
||||
|
||||
management:
|
||||
endpoint:
|
||||
health:
|
||||
probes:
|
||||
enabled: true
|
||||
show-details: always
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health
|
||||
health:
|
||||
livenessState:
|
||||
enabled: true
|
||||
readinessState:
|
||||
enabled: true
|
||||
@@ -0,0 +1,171 @@
|
||||
spring:
|
||||
application:
|
||||
name: it-asset-management
|
||||
|
||||
service:
|
||||
token:
|
||||
enabled: true
|
||||
|
||||
# =============================
|
||||
# MySQL Database Configuration
|
||||
# =============================
|
||||
datasource:
|
||||
url: jdbc:mysql://192.168.3.144:3306/itassetmanagement?createDatabaseIfNotExist=true
|
||||
username: app_user
|
||||
password: userpassword123
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
hikari:
|
||||
connectionTimeout: 20000
|
||||
maximumPoolSize: 20
|
||||
|
||||
jpa:
|
||||
database-platform: org.hibernate.dialect.MySQL8Dialect
|
||||
hibernate:
|
||||
ddl-auto: update # Options: none, validate, update, create, create-drop
|
||||
show-sql: true
|
||||
defer-datasource-initialization: false
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
|
||||
sql:
|
||||
init:
|
||||
schema-locations:
|
||||
- classpath:activiti.engine.schema.sql
|
||||
mode: always
|
||||
|
||||
# =============================
|
||||
# Redis Configuration
|
||||
# =============================
|
||||
data:
|
||||
redis:
|
||||
host: 192.168.3.144
|
||||
port: 6379
|
||||
password: redispassword123
|
||||
database: 0
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 10
|
||||
max-idle: 8
|
||||
min-idle: 2
|
||||
max-wait: 5s
|
||||
|
||||
# =============================
|
||||
# MongoDB Configuration
|
||||
# =============================
|
||||
mongodb:
|
||||
host: 192.168.3.144
|
||||
port: 27017
|
||||
username: root
|
||||
password: mongopassword123
|
||||
authentication-database: admin
|
||||
|
||||
mongodb:
|
||||
client:
|
||||
settings:
|
||||
connection-pool:
|
||||
max-size: 500
|
||||
min-size: 10
|
||||
max-connection-idle-time: 10s
|
||||
max-wait-time: 5s
|
||||
|
||||
# =============================
|
||||
# Kafka Configuration
|
||||
# =============================
|
||||
kafka:
|
||||
bootstrap-servers: 192.168.3.144:9092
|
||||
properties:
|
||||
schema:
|
||||
registry:
|
||||
url: http://192.168.3.144:8081
|
||||
specific:
|
||||
avro:
|
||||
reader: true
|
||||
producer:
|
||||
key-serializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
value-serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
|
||||
consumer:
|
||||
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
||||
value-deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
|
||||
group-id: ${spring.application.name}-consumer-group
|
||||
auto-offset-reset: earliest
|
||||
|
||||
# =============================
|
||||
# Security Configuration
|
||||
# =============================
|
||||
security:
|
||||
oauth2:
|
||||
resourceserver:
|
||||
jwt:
|
||||
issuer-uri: https://holocron.keross.com/api/platform
|
||||
|
||||
|
||||
# =============================
|
||||
# IKON Platform Configurations
|
||||
# =============================
|
||||
ikon:
|
||||
user:
|
||||
agent: "IKON App Server"
|
||||
time-zone: "Asia/Kolkata"
|
||||
platform:
|
||||
rest:
|
||||
url: https://holocron.keross.com/api/platform
|
||||
logger:
|
||||
enabled: false # set true when deployed in dev/uat/prod otherwise set to false if running in local/devtools environment.
|
||||
app:
|
||||
softwareId: "00065ac0-32ea-4978-8ab1-5402f041413c"
|
||||
softwareVersion: 1
|
||||
softwareName: "IT Asset Management"
|
||||
softwareRepositoryName: "it-asset-management"
|
||||
accessmanagement:
|
||||
init:
|
||||
file: ../../bpmn/project.json
|
||||
|
||||
|
||||
# =============================
|
||||
# Logging Configuration
|
||||
# =============================
|
||||
logging:
|
||||
level:
|
||||
com.ikon: DEBUG
|
||||
file:
|
||||
name: "../logs/${spring.application.name}-app.log"
|
||||
|
||||
|
||||
# =============================
|
||||
# Server Configuration
|
||||
# =============================
|
||||
server:
|
||||
address: localhost
|
||||
port: 8072
|
||||
|
||||
|
||||
# =============================
|
||||
# Eureka (Optional)
|
||||
# =============================
|
||||
eureka:
|
||||
instance:
|
||||
ip-address: ${server.address}
|
||||
preferIpAddress: true
|
||||
instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
|
||||
client:
|
||||
register-with-eureka: false
|
||||
fetch-registry: false
|
||||
service-url:
|
||||
default-zone: http://localhost:8761/eureka
|
||||
|
||||
management:
|
||||
endpoint:
|
||||
health:
|
||||
probes:
|
||||
enabled: true
|
||||
show-details: always
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health
|
||||
health:
|
||||
livenessState:
|
||||
enabled: true
|
||||
readinessState:
|
||||
enabled: true
|
||||
@@ -0,0 +1,7 @@
|
||||
spring:
|
||||
application:
|
||||
name: it-asset-management
|
||||
jpa:
|
||||
open-in-view: false
|
||||
profiles:
|
||||
active: sharedserver
|
||||
Reference in New Issue
Block a user