@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public RESTResponse<PolicyEntity> createOrUpdatePolicyProto(PolicyEntity policyProto) { return RESTResponse.async(() -> policyEntityService.createOrUpdatePolicyProto(policyProto)).get(); }
@DELETE @Path("/{uuid}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public RESTResponse<Boolean> deletePolicyProto(@PathParam("uuid") String uuid) { return RESTResponse.async(() -> policyEntityService.deletePolicyProtoByUUID(uuid)).get(); }
@POST @Path("/exportByName/{site}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public RESTResponse<Boolean> loadPoliciesByName(List<String> policyProtoList, @PathParam("site") String site) { return RESTResponse.async(() -> { if (policyProtoList == null || policyProtoList.isEmpty()) { throw new IllegalArgumentException("policyProtoList is null or empty"); } List<PolicyEntity> policyEntities = new ArrayList<PolicyEntity>(); for (String name : policyProtoList) { PolicyEntity entity = policyEntityService.getByUUIDorName(null, name); if (entity != null) { policyEntities.add(entity); } } return exportPolicyProto(policyEntities, site); }).get(); }
default PolicyEntity createOrUpdatePolicyProto(PolicyEntity policyProto) { Preconditions.checkNotNull(policyProto, "PolicyProto should not be null"); Preconditions.checkNotNull(policyProto.getDefinition(), "PolicyProto definition should not be null"); if (policyProto.getName() == null) { policyProto.setName(String.format("[%s]%s", policyProto.getDefinition().getAlertCategory(), policyProto.getDefinition().getName())); } if (policyProto.getUuid() == null) { return create(policyProto); } else { return update(policyProto); } }
private PolicyEntity importPolicyProto(PolicyEntity policyEntity) { PolicyDefinition policyDefinition = policyEntity.getDefinition(); checkOutputStream(policyDefinition.getInputStreams(), policyDefinition.getOutputStreams()); List<String> inputStreamType = new ArrayList<>(); String newDefinition = policyDefinition.getDefinition().getValue(); for (String inputStream : policyDefinition.getInputStreams()) { String streamDef = StreamIdConversions.parseStreamTypeId(policyDefinition.getSiteId(), inputStream); inputStreamType.add(streamDef); newDefinition = newDefinition.replaceAll(inputStream, streamDef); } policyDefinition.setInputStreams(inputStreamType); policyDefinition.getDefinition().setValue(newDefinition); policyDefinition.setName(PolicyIdConversions.parsePolicyId(policyDefinition.getSiteId(), policyDefinition.getName())); policyDefinition.setSiteId(null); policyDefinition.getPartitionSpec().clear(); policyEntity.setDefinition(policyDefinition); return policyEntityService.createOrUpdatePolicyProto(policyEntity); }