List<AuditRule> findByDevice(Device device);
+ void deleteByDeviceAndKey(Device device, String key);
+
}
import com.samsung.samserver.domain.primary.AuditRule;
import com.samsung.samserver.domain.primary.Device;
-import java.util.List;
+import java.util.*;
/**
* Service Interface for managing AuditRule.
*
* @param device the Device entity
* @return the list of AuditRule entities
- */ List<AuditRule> find(Device device);
+ */
+ List<AuditRule> find(Device device);
+
+ /**
+ * Get the set AuditRule key by Device.
+ *
+ * @param device the Device entity
+ * @return the set of AuditRule key
+ */
+ Set<String> getKeys(Device device);
+
+ /**
+ * Delete a device auditRule.
+ *
+ * @param device the Device entity
+ * @param key the AuditRule key
+ */
+ void delete(Device device, String key);
}
import org.springframework.transaction.annotation.Transactional;
import java.time.Instant;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
/**
* Service Implementation for managing AuditRule.
return auditRuleRepository.findByDevice(device);
}
+ /**
+ * Get the set AuditRule key by Device.
+ *
+ * @param device the Device entity
+ * @return the set of AuditRule key
+ */
+ @Override
+ public Set<String> getKeys(Device device){
+ log.debug("Request to get set AuditRule key by device: {}", device.getId());
+ Set<String> result = new HashSet<>();
+ List<AuditRule> auditRuleList = auditRuleRepository.findByDevice(device);
+ for (AuditRule auditRule: auditRuleList) {
+ result.add(auditRule.getKey());
+ }
+ return result;
+ }
+
+ /**
+ * Delete a device auditRule.
+ *
+ * @param device the Device entity
+ * @param key the AuditRule key
+ */
+ @Override
+ public void delete(Device device, String key) {
+ log.debug("Request to delete AuditRule: device: {}, key: {}", device.getId(), key);
+ auditRuleRepository.deleteByDeviceAndKey(device, key);
+ }
+
}
\ No newline at end of file
import javax.validation.Valid;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
import static com.samsung.samserver.web.rest.service.vm.UIAuditRules.UIAuditRule;
throw new DeviceServiceError.DeviceNotFoundException();
}
+ Set<String> auditRuleKeys = auditRuleService.getKeys(device);
+ auditRuleKeys.removeAll(uiAuditRulesUpdate.getKeys());
+ for (String key : auditRuleKeys) {
+ auditRuleService.delete(device, key);
+ }
+
int c = 0;
ObjectMapper mapper = new ObjectMapper();
List<UIAuditRule> resultAuditRulesUpdate = new ArrayList<>();
import com.fasterxml.jackson.annotation.JsonProperty;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
-import java.util.List;
+import java.util.*;
import lombok.*;
import static com.samsung.samserver.web.rest.service.vm.UIAuditRules.*;
@JsonProperty("rules")
private List<UIAuditRule> uiAuditRuleList;
+ public Set<String> getKeys(){
+ Set<String> result = new HashSet<>();
+ for (UIAuditRule uiAuditRule: uiAuditRuleList) {
+ result.add(uiAuditRule.getKey());
+ }
+ return result;
+ }
+
}
\ No newline at end of file