// Regex for acceptable logins
public static final String LOGIN_REGEX = "^[_'.@A-Za-z0-9-]*$";
+ public static final String DEVICE_LOCKED_REGEX = "[0-1]";
public static final String SYSTEM_ACCOUNT = "system";
public static final String ANONYMOUS_USER = "anonymoususer";
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.Instant;
import java.util.*;
+
+import com.samsung.samserver.config.Constants;
import lombok.*;
/**
@Column(name = "descr")
private String descr;
+ //@Pattern(regexp = Constants.DEVICE_LOCKED_REGEX)
+ //@Size(min = 1, max = 1)
@Column(name = "jhi_locked")
private String locked;
import com.samsung.samserver.web.rest.service.*;
import com.samsung.samserver.web.rest.errors.UserServiceError;
+import com.samsung.samserver.web.rest.service.ui.GetDevicesRestService;
+import com.samsung.samserver.web.rest.service.ui.UpdateDevicesRestService;
import org.springframework.data.domain.Pageable;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
})
@RequestMapping(value ="/devices", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
- public ResponseEntity<List<GetDevicesUIRestService.UIDevice>> getAllDevices(Pageable pageable);
+ public ResponseEntity<List<GetDevicesRestService.UIDevice>> getAllDevices(Pageable pageable);
/**
public ResponseEntity<Void> logout();
+ /**
+ * PUT /devices/update : Updates an existing devices.
+ *
+ * @param uiDeviceUpdate list the device info to update
+ * @return the ResponseEntity with status 200 (OK)
+ * or with status 400 (Bad Request) if the uiDeviceUpdate is not valid
+ */
+ @ApiOperation(value = "devices/update", notes = "The “devices update” operation is used to update devices.")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK. Devices was updated successfully."),
+ @ApiResponse(code = 400, message = "Bad Request. The reason is contained in the tags “errorKey”, “message”, “title”"),
+ @ApiResponse(code = 500, message = "Internal server error. The user has to repeat action.")
+ })
+ @RequestMapping(value ="/devices/update", method = RequestMethod.PUT)
+ public ResponseEntity<Void> updateDevice(@Valid @RequestBody List<UpdateDevicesRestService.UIDeviceUpdate> uiDeviceUpdate);
+
}
import com.samsung.samserver.service.DeviceService;
import com.samsung.samserver.web.rest.controller.IRestDashboard;
import com.samsung.samserver.web.rest.service.*;
+import com.samsung.samserver.web.rest.service.ui.GetDevicesRestService;
+import com.samsung.samserver.web.rest.service.ui.UpdateDevicesRestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.*;
private AccountService accountService;
@Autowired
- private GetDevicesUIRestService getDevicesUIRestService;
+ private GetDevicesRestService getDevicesRestService;
+
+ @Autowired
+ private UpdateDevicesRestService updateDevicesRestService;
/**
* GET /devices : get all the devices.
* @return the ResponseEntity with status 200 (OK) and the list of devices in body
*/
@Override
- public ResponseEntity<List<GetDevicesUIRestService.UIDevice>> getAllDevices(Pageable pageable) {
- return getDevicesUIRestService.getAllDevices(pageable);
+ public ResponseEntity<List<GetDevicesRestService.UIDevice>> getAllDevices(Pageable pageable) {
+ return getDevicesRestService.getAllDevices(pageable);
}
/**
return ResponseEntity.ok().headers(new HttpHeaders()).build();
}
+ /**
+ * PUT /devices/update : Updates an existing devices.
+ *
+ * @param uiDeviceUpdate list the device info to update
+ * @return the ResponseEntity with status 200 (OK)
+ * or with status 400 (Bad Request) if the uiDeviceUpdate is not valid
+ */
+ @Override
+ public ResponseEntity<Void> updateDevice(@Valid @RequestBody List<UpdateDevicesRestService.UIDeviceUpdate> uiDeviceUpdate) {
+ return updateDevicesRestService.updateDevice(uiDeviceUpdate);
+ }
+
}
* LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*/
-package com.samsung.samserver.web.rest.service;
+package com.samsung.samserver.web.rest.service.ui;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.samsung.samserver.domain.Device;
* @version 1.0
*/
@Service
-public class GetDevicesUIRestService {
+public class GetDevicesRestService {
- private final Logger log = LoggerFactory.getLogger(GetDevicesUIRestService.class);
+ private final Logger log = LoggerFactory.getLogger(GetDevicesRestService.class);
@Autowired
private DeviceService deviceService;
@Autowired
private GeoIPService geoIPService;
- public ResponseEntity<List<GetDevicesUIRestService.UIDevice>> getAllDevices(Pageable pageable) {
+ public ResponseEntity<List<GetDevicesRestService.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<>();
+ List<GetDevicesRestService.UIDevice> uiDevices = new ArrayList<>();
for (Device device: devices) {
UIDevice uiDevice = new UIDevice();
uiDevice.setId(device.getId());
--- /dev/null
+/*
+ * In Samsung Ukraine R&D Center (SRK under a contract between)
+ * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ */
+package com.samsung.samserver.web.rest.service.ui;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.samsung.samserver.config.Constants;
+import com.samsung.samserver.domain.Device;
+import com.samsung.samserver.service.DeviceService;
+import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.*;
+import org.slf4j.*;
+import java.util.List;
+import lombok.*;
+
+import javax.validation.Valid;
+import javax.validation.constraints.*;
+
+/**
+ * REST service implementation for get updates.
+ *
+ * @author <A HREF="mailto:m.dalakov@samsung.com">Mykhailo Dalakov</A>
+ * @version 1.0
+ */
+@Service
+public class UpdateDevicesRestService {
+
+ private final Logger log = LoggerFactory.getLogger(UpdateDevicesRestService.class);
+
+ @Autowired
+ private DeviceService deviceService;
+
+ public ResponseEntity<Void> updateDevice(@Valid @RequestBody List<UpdateDevicesRestService.UIDeviceUpdate> uiDeviceUpdate) {
+ log.debug("UI request to update devices : {}", uiDeviceUpdate);
+ for (UIDeviceUpdate update: uiDeviceUpdate) {
+ Device d = deviceService.findOne(update.getId());
+ if (d!=null) {
+ d.setLocked(update.getLocked().toString());
+ deviceService.save(d);
+ }
+ }
+ return ResponseEntity.ok().headers(new HttpHeaders()).build();
+ }
+
+ @Getter @Setter @ToString
+ public static class UIDeviceUpdate {
+ private Long id;
+ @Pattern(regexp = Constants.DEVICE_LOCKED_REGEX)
+ @Size(min = 1, max = 1)
+ private Integer locked;
+ }
+
+}
\ No newline at end of file