duid String,
ctime Instant,
model String,
- location String,
+ ipaddr String,
sn String,
descr String,
locked String,
@Column(name = "model")
private String model;
- @Column(name = "location")
- private String location;
+ @Column(name = "ipaddr")
+ private String ipaddr;
@Column(name = "sn")
private String sn;
- @Column(name = "descr")
- private String descr;
-
- @Column(name = "jhi_locked")
- private String locked;
-
@Column(name = "sw")
private String sw;
@Column(name = "osver")
private String osver;
+ @Column(name = "descr")
+ private String descr;
+
+ @Column(name = "jhi_locked")
+ private String locked;
+
@OneToMany(mappedBy = "device")
@JsonIgnore
private Set<Report> reports = new HashSet<>();
@JsonIgnore
private Policy policy;
- public Device() {
- }
-
- public Device(String duid, String model, String location, String sn, String descr,
- DeviceType dtype, String sw, String osname, String osver) {
- this.duid = duid;
- this.model = model;
- this.location = location;
- this.sn = sn;
- this.descr = descr;
- this.dtype = dtype;
- this.ctime = Instant.now();
- this.sw = sw;
- this.osname = osname;
- this.osver = osver;
- }
-
public Device duid(String duid) {
this.duid = duid;
return this;
return this;
}
- public Device location(String location) {
- this.location = location;
+ public Device ipaddr(String ipaddr) {
+ this.ipaddr = ipaddr;
return this;
}
return this;
}
+ public Device sw(String sw) {
+ this.sw = sw;
+ return this;
+ }
+
+ public Device osname(String osname) {
+ this.osname = osname;
+ return this;
+ }
+
+ public Device osver(String osver) {
+ this.osver = osver;
+ return this;
+ }
+
public Device descr(String descr) {
this.descr = descr;
return this;
package com.samsung.samserver.service;
import com.samsung.samserver.domain.Device;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
import java.util.List;
import java.util.Optional;
*/
List<Device> findAll();
+
+ /**
+ * Get page of all the devices.
+ *
+ * @return the page of entities
+ */
+ Page<Device> findAll(Pageable pageable);
+
/**
* Get the "id" device.
*
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
}
/**
+ * Get page of all the devices.
+ *
+ * @return the page of entities
+ */
+ @Override
+ @Transactional(readOnly = true)
+ public Page<Device> findAll(Pageable pageable) {
+ log.debug("Request to get page of all Devices"); //NOSONAR
+ return deviceRepository.findAll(pageable);
+ }
+
+ /**
* Get one device by id.
*
* @param id the id of the entity
import com.samsung.samserver.web.rest.service.*;
import com.samsung.samserver.web.rest.errors.UserServiceError;
+import org.springframework.data.domain.Pageable;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
})
@RequestMapping(value ="/devices", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
- public ResponseEntity<List<GetDevicesUIRestService.UIDevice>> getAllDevices();
+ public ResponseEntity<List<GetDevicesUIRestService.UIDevice>> getAllDevices(Pageable pageable);
/**
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
+import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
@RequestMapping(value ="/register-device", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<String> registerDevice(
- @ApiParam(value = "Device info", required = true) @Valid @RequestBody RegisterDeviceRestService.DInfo dInfo);
+ @ApiParam(value = "Device info", required = true) @Valid @RequestBody RegisterDeviceRestService.DInfo dInfo, HttpServletRequest request);
/*
import com.samsung.samserver.web.rest.controller.IRestDashboard;
import com.samsung.samserver.web.rest.service.*;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
* @return the ResponseEntity with status 200 (OK) and the list of devices in body
*/
@Override
- public ResponseEntity<List<GetDevicesUIRestService.UIDevice>> getAllDevices() {
- return getDevicesUIRestService.getAllDevices();
+ public ResponseEntity<List<GetDevicesUIRestService.UIDevice>> getAllDevices(Pageable pageable) {
+ return getDevicesUIRestService.getAllDevices(pageable);
}
/**
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
private SendDataRestService sendDataRestService;
@Override
- public ResponseEntity<String> registerDevice(@Valid @RequestBody RegisterDeviceRestService.DInfo dInfo) {
- return registerDeviceRestService.registerDevice(dInfo);
+ public ResponseEntity<String> registerDevice(@Valid @RequestBody RegisterDeviceRestService.DInfo dInfo, HttpServletRequest request) {
+ return registerDeviceRestService.registerDevice(dInfo, request);
}
@Override
import com.fasterxml.jackson.annotation.JsonProperty;
import com.samsung.samserver.domain.Device;
import com.samsung.samserver.service.DeviceService;
+import com.samsung.samserver.web.rest.util.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.http.*;
import org.slf4j.*;
@Autowired
private DeviceService deviceService;
- public ResponseEntity<List<GetDevicesUIRestService.UIDevice>> getAllDevices() {
- log.debug("UI request to get all devices"); //NO_SONAR
- List<Device> devices = deviceService.findAll();
+ public ResponseEntity<List<GetDevicesUIRestService.UIDevice>> getAllDevices(Pageable pageable) {
+ log.debug("UI request to get all devices"); //NOSONAR
+ Page<Device> devices = deviceService.findAll(pageable);
List<GetDevicesUIRestService.UIDevice> uiDevices = new ArrayList<>();
for (Device device: devices) {
UIDevice uiDevice = new UIDevice();
uiDevice.setDuid(device.getDuid());
uiDevice.setCtime(device.getCtime());
uiDevice.setModel(device.getModel());
- uiDevice.setLocation("UA"/*device.getLocation()*/);
+ uiDevice.setIpaddr(device.getIpaddr());
uiDevice.setSn(device.getSn());
uiDevice.setDescr(device.getDescr());
uiDevice.setLocked(device.getLocked()!=null && !device.getLocked().equals("0") ? 1:0);
uiDevice.setUiDeviceType(new UIDeviceType (device.getDtype().getName(), device.getDtype().getDescr()));
uiDevices.add(uiDevice);
}
- final HttpHeaders httpHeaders = new HttpHeaders();
- httpHeaders.setContentType(MediaType.APPLICATION_JSON);
- return new ResponseEntity<>(uiDevices , httpHeaders, HttpStatus.OK);
+ Page<UIDevice> page = new PageImpl(uiDevices, pageable, devices.getTotalPages());
+ HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/dashboard/devices");
+ return new ResponseEntity<>(page.getContent() , headers, HttpStatus.OK);
}
@Getter @Setter @ToString
@JsonProperty("model")
private String model;
- @JsonProperty("location")
- private String location;
+ @JsonProperty("ipaddr")
+ private String ipaddr;
@JsonProperty("sn")
private String sn;
import com.samsung.samserver.domain.*;
import com.samsung.samserver.service.*;
import com.samsung.samserver.web.rest.errors.DeviceServiceError;
+
+import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
+import java.time.Instant;
import java.util.Optional;
import lombok.*;
this.deviceService = deviceService;
}
- public ResponseEntity<String> registerDevice(@Valid @RequestBody DInfo dInfo) {
+ public ResponseEntity<String> registerDevice(@Valid @RequestBody DInfo dInfo, HttpServletRequest request) {
log.debug("request to register device : {}", dInfo);
String dtype = dInfo.getType().toLowerCase();
String duid = deviceService.getDeviceUID(dtype, dInfo.getModel(), dInfo.getSn());
deviceService.findOne(duid).ifPresent(d -> {throw new DeviceServiceError.DeviceAlreadyRegisteredException();});
- Device result = deviceService.save(
- new Device(duid, dInfo.getModel(), dInfo.getLocation(), dInfo.getSn(), dInfo.getDescr(), dt.get(),
- dInfo.getSw(), dInfo.getOsname(), dInfo.getOsver()));
-
+ Device result = deviceService.save(new Device()
+ .duid(duid)
+ .ctime(Instant.now())
+ .model(dInfo.getModel())
+ .sn(dInfo.getSn())
+ .sw(dInfo.getSw())
+ .osname(dInfo.getOsname())
+ .osver(dInfo.getOsver())
+ .ipaddr(request.getRemoteAddr())
+ .descr(dInfo.getDescr())
+ .dtype(dt.get()));
return ResponseEntity.ok()
.headers(new HttpHeaders())
.body(result.getDuid());
@NotNull
private String model;
- @JsonProperty("location")
- private String location;
+ @JsonProperty("ipaddr")
+ private String ipaddr;
@JsonProperty("sn")
@NotNull
<constraints nullable="true" />
</column>
- <column name="location" type="varchar(255)">
+ <column name="ipaddr" type="varchar(255)">
<constraints nullable="true" />
</column>
private static final String DEFAULT_MODEL = "AAAAAAAAAA";
private static final String UPDATED_MODEL = "BBBBBBBBBB";
- private static final String DEFAULT_LOCATION = "AAAAAAAAAA";
- private static final String UPDATED_LOCATION = "BBBBBBBBBB";
+ private static final String DEFAULT_IPADDR = "AAAAAAAAAA";
+ private static final String UPDATED_IPADDR = "BBBBBBBBBB";
private static final String DEFAULT_SN = "AAAAAAAAAA";
private static final String UPDATED_SN = "BBBBBBBBBB";
.duid(DEFAULT_DUID)
.ctime(DEFAULT_CTIME)
.model(DEFAULT_MODEL)
- .location(DEFAULT_LOCATION)
+ .ipaddr(DEFAULT_IPADDR)
.sn(DEFAULT_SN)
.descr(DEFAULT_DESCR)
.locked(DEFAULT_LOCKED);
assertThat(testDevice.getDuid()).isEqualTo(DEFAULT_DUID);
assertThat(testDevice.getCtime()).isEqualTo(DEFAULT_CTIME);
assertThat(testDevice.getModel()).isEqualTo(DEFAULT_MODEL);
- assertThat(testDevice.getLocation()).isEqualTo(DEFAULT_LOCATION);
+ assertThat(testDevice.getIpaddr()).isEqualTo(DEFAULT_IPADDR);
assertThat(testDevice.getSn()).isEqualTo(DEFAULT_SN);
assertThat(testDevice.getDescr()).isEqualTo(DEFAULT_DESCR);
assertThat(testDevice.getLocked()).isEqualTo(DEFAULT_LOCKED);
.andExpect(jsonPath("$.[*].duid").value(hasItem(DEFAULT_DUID.toString())))
.andExpect(jsonPath("$.[*].ctime").value(hasItem(DEFAULT_CTIME.toString())))
.andExpect(jsonPath("$.[*].model").value(hasItem(DEFAULT_MODEL.toString())))
- .andExpect(jsonPath("$.[*].location").value(hasItem(DEFAULT_LOCATION.toString())))
+ .andExpect(jsonPath("$.[*].ipaddr").value(hasItem(DEFAULT_IPADDR.toString())))
.andExpect(jsonPath("$.[*].sn").value(hasItem(DEFAULT_SN.toString())))
.andExpect(jsonPath("$.[*].descr").value(hasItem(DEFAULT_DESCR.toString())))
.andExpect(jsonPath("$.[*].locked").value(hasItem(DEFAULT_LOCKED.toString())));
.andExpect(jsonPath("$.duid").value(DEFAULT_DUID.toString()))
.andExpect(jsonPath("$.ctime").value(DEFAULT_CTIME.toString()))
.andExpect(jsonPath("$.model").value(DEFAULT_MODEL.toString()))
- .andExpect(jsonPath("$.location").value(DEFAULT_LOCATION.toString()))
+ .andExpect(jsonPath("$.ipaddr").value(DEFAULT_IPADDR.toString()))
.andExpect(jsonPath("$.sn").value(DEFAULT_SN.toString()))
.andExpect(jsonPath("$.descr").value(DEFAULT_DESCR.toString()))
.andExpect(jsonPath("$.locked").value(DEFAULT_LOCKED.toString()));
.duid(UPDATED_DUID)
.ctime(UPDATED_CTIME)
.model(UPDATED_MODEL)
- .location(UPDATED_LOCATION)
+ .ipaddr(UPDATED_IPADDR)
.sn(UPDATED_SN)
.descr(UPDATED_DESCR)
.locked(UPDATED_LOCKED);
assertThat(testDevice.getDuid()).isEqualTo(UPDATED_DUID);
assertThat(testDevice.getCtime()).isEqualTo(UPDATED_CTIME);
assertThat(testDevice.getModel()).isEqualTo(UPDATED_MODEL);
- assertThat(testDevice.getLocation()).isEqualTo(UPDATED_LOCATION);
+ assertThat(testDevice.getIpaddr()).isEqualTo(UPDATED_IPADDR);
assertThat(testDevice.getSn()).isEqualTo(UPDATED_SN);
assertThat(testDevice.getDescr()).isEqualTo(UPDATED_DESCR);
assertThat(testDevice.getLocked()).isEqualTo(UPDATED_LOCKED);