@Override public boolean equals(Object that) { if (that == this) { return true; } if (!(that instanceof PolicyEntity)) { return false; } PolicyEntity another = (PolicyEntity) that; return Objects.equals(another.name, this.name) && Objects.equals(another.definition, this.definition) && CollectionUtils.isEqualCollection(another.getAlertPublishmentIds(), alertPublishmentIds); }
@POST @Path("/create") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public RESTResponse<PolicyEntity> saveAsPolicyProto(PolicyEntity policyEntity, @QueryParam("needPolicyProtoCreated") boolean needPolicyProtoCreated) { return RESTResponse.async(() -> { Preconditions.checkNotNull(policyEntity, "entity should not be null"); Preconditions.checkNotNull(policyEntity.getDefinition(), "policy definition should not be null"); Preconditions.checkNotNull(policyEntity.getAlertPublishmentIds(), "alert publisher list should not be null"); PolicyDefinition policyDefinition = policyEntity.getDefinition(); checkOutputStream(policyDefinition.getInputStreams(), policyDefinition.getOutputStreams()); OpResult result = metadataResource.addPolicy(policyDefinition); if (result.code != 200) { throw new IllegalArgumentException(result.message); } result = metadataResource.addPublishmentsToPolicy(policyDefinition.getName(), policyEntity.getAlertPublishmentIds()); if (result.code != 200) { throw new IllegalArgumentException(result.message); } if (needPolicyProtoCreated) { importPolicyProto(policyEntity); } return policyEntity; }).get(); }
@Override public PolicyEntity update(PolicyEntity policyProto) { Preconditions.checkNotNull(policyProto, "Entity should not be null"); Preconditions.checkNotNull(policyProto.getUuid(), "uuid should not be null"); PolicyEntity current = getByUUIDorName(policyProto.getUuid(), null); if (policyProto.getName() != null) { current.setName(policyProto.getName()); } if (policyProto.getAlertPublishmentIds() != null) { current.setAlertPublishmentIds(policyProto.getAlertPublishmentIds()); } if (policyProto.getDefinition() != null) { current.setDefinition(policyProto.getDefinition()); } current.ensureDefault(); try { if (!queryService.execute(updateSqlByUUID, current, policyEntityWriter)) { throw new IllegalArgumentException("Failed to update policyProto"); } } catch (SQLException e) { LOGGER.error("Error to execute {}: {}", updateSqlByUUID, policyProto, e); throw new IllegalArgumentException("SQL execution error: " + e.getMessage(), e); } return current; }
throw new IllegalArgumentException("fail to create policy: " + result.message); if (policyProto.getAlertPublishmentIds() != null && !policyProto.getAlertPublishmentIds().isEmpty()) { result = metadataResource.addPublishmentsToPolicy(policyDefinition.getName(), policyProto.getAlertPublishmentIds()); if (result.code != 200) { throw new IllegalArgumentException("fail to create policy publisherments: " + result.message);