List of usage examples for java.util LinkedHashMap clear
public void clear()
From source file:com.ikanow.aleph2.analytics.services.TestDeduplicationService.java
@SuppressWarnings("unchecked") @Test/*from w ww . j a va 2s . c o m*/ public void test_handleDuplicateRecord() { final IEnrichmentModuleContext enrich_context = Mockito.mock(IEnrichmentModuleContext.class); Mockito.when(enrich_context.emitImmutableObject(Mockito.any(Long.class), Mockito.any(JsonNode.class), Mockito.any(Optional.class), Mockito.any(Optional.class), Mockito.any(Optional.class))) .thenReturn(Validation.success(_mapper.createObjectNode())); TestDedupEnrichmentModule test_module = new TestDedupEnrichmentModule(); final String ts_field = "@timestamp"; final ObjectNode old_json = _mapper.createObjectNode(); old_json.put("_id", "old_record"); old_json.put("@timestamp", 0L); old_json.put("url", "test"); final ObjectNode new_json = _mapper.createObjectNode(); new_json.put("@timestamp", 1L); new_json.put("url", "test"); final ObjectNode new_json_but_same_time = _mapper.createObjectNode(); new_json_but_same_time.put("@timestamp", 0L); new_json_but_same_time.put("url", "test"); Tuple3<Long, IBatchRecord, ObjectNode> new_record = Tuples._3T(0L, new BatchRecordUtils.JsonBatchRecord(new_json), _mapper.createObjectNode()); Tuple3<Long, IBatchRecord, ObjectNode> new_record_but_same_time = Tuples._3T(0L, new BatchRecordUtils.JsonBatchRecord(new_json_but_same_time), _mapper.createObjectNode()); new_record._2().getContent(); //(code coverage!) final TextNode key = new TextNode("url"); LinkedHashMap<JsonNode, LinkedList<Tuple3<Long, IBatchRecord, ObjectNode>>> mutable_obj_map = new LinkedHashMap<>(); final LinkedList<Tuple3<Long, IBatchRecord, ObjectNode>> new_records = Stream.of(new_record) .collect(Collectors.toCollection(LinkedList::new)); final LinkedList<Tuple3<Long, IBatchRecord, ObjectNode>> new_records_but_same_time = Stream .of(new_record_but_same_time).collect(Collectors.toCollection(LinkedList::new)); // Simple case Leave policy { //(reset) mutable_obj_map.clear(); mutable_obj_map.put(new TextNode("never_changed"), new_records); mutable_obj_map.put(new TextNode("url"), new_records); assertEquals(2, mutable_obj_map.size()); new_record._3().removeAll(); new_record_but_same_time._3().removeAll(); _called_batch.set(0); DocumentSchemaBean config = BeanTemplateUtils.build(DocumentSchemaBean.class) .with(DocumentSchemaBean::deduplication_policy, DeduplicationPolicy.leave).done().get(); DeduplicationEnrichmentContext test_context = new DeduplicationEnrichmentContext(enrich_context, config, j -> Optional.empty()); final Stream<JsonNode> ret_val = DeduplicationService.handleDuplicateRecord(config, Optional.of(Tuples._2T(test_module, test_context)), ts_field, new_records, Arrays.asList(old_json), key, mutable_obj_map); assertEquals(0L, ret_val.count()); // Nothing emitted Mockito.verify(enrich_context, Mockito.times(0)).emitImmutableObject(Mockito.any(Long.class), Mockito.any(JsonNode.class), Mockito.any(Optional.class), Mockito.any(Optional.class), Mockito.any(Optional.class)); // No custom processing performed assertEquals(0, _called_batch.get()); // No annotations/mutations assertEquals("{}", new_record._3().toString()); // Object removed from mutable map assertEquals(1, mutable_obj_map.size()); } // Simple case update policy - time updates final Consumer<Boolean> test_time_updates = delete_unhandled -> { //(reset) mutable_obj_map.clear(); mutable_obj_map.put(new TextNode("never_changed"), new_records); mutable_obj_map.put(new TextNode("url"), new_records); assertEquals(2, mutable_obj_map.size()); new_record._3().removeAll(); new_record_but_same_time._3().removeAll(); _called_batch.set(0); DocumentSchemaBean config = BeanTemplateUtils.build(DocumentSchemaBean.class) .with(DocumentSchemaBean::deduplication_policy, DeduplicationPolicy.update) .with(DocumentSchemaBean::delete_unhandled_duplicates, delete_unhandled).done().get(); DeduplicationEnrichmentContext test_context = new DeduplicationEnrichmentContext(enrich_context, config, j -> Optional.empty()); // (add the same object twice to test the "return ids to delete" functionality) final Stream<JsonNode> ret_val = DeduplicationService.handleDuplicateRecord(config, Optional.of(Tuples._2T(test_module, test_context)), ts_field, new_records, Arrays.asList(old_json, old_json), key, mutable_obj_map); if (delete_unhandled) { assertEquals(Arrays.asList("old_record"), ret_val.sorted() .map(j -> DeduplicationService.jsonToObject(j)).collect(Collectors.toList())); } else { assertEquals(0L, ret_val.count()); } // Nothing emitted Mockito.verify(enrich_context, Mockito.times(0)).emitImmutableObject(Mockito.any(Long.class), Mockito.any(JsonNode.class), Mockito.any(Optional.class), Mockito.any(Optional.class), Mockito.any(Optional.class)); // No custom processing performed assertEquals(0, _called_batch.get()); // _id assertEquals("{\"_id\":\"old_record\"}", new_record._3().toString()); // Object removed from mutable map assertEquals(2, mutable_obj_map.size()); }; test_time_updates.accept(true); test_time_updates.accept(false); // Simple case update policy - times the same { //(reset) mutable_obj_map.clear(); mutable_obj_map.put(new TextNode("never_changed"), new_records); mutable_obj_map.put(new TextNode("url"), new_records); new_record._3().removeAll(); new_record_but_same_time._3().removeAll(); _called_batch.set(0); DocumentSchemaBean config = BeanTemplateUtils.build(DocumentSchemaBean.class) .with(DocumentSchemaBean::deduplication_policy, DeduplicationPolicy.update) .with(DocumentSchemaBean::delete_unhandled_duplicates, false).done().get(); DeduplicationEnrichmentContext test_context = new DeduplicationEnrichmentContext(enrich_context, config, j -> Optional.empty()); final Stream<JsonNode> ret_val = DeduplicationService.handleDuplicateRecord(config, Optional.of(Tuples._2T(test_module, test_context)), ts_field, new_records_but_same_time, Arrays.asList(old_json), key, mutable_obj_map); assertEquals(0L, ret_val.count()); // Nothing emitted Mockito.verify(enrich_context, Mockito.times(0)).emitImmutableObject(Mockito.any(Long.class), Mockito.any(JsonNode.class), Mockito.any(Optional.class), Mockito.any(Optional.class), Mockito.any(Optional.class)); // No custom processing performed assertEquals(0, _called_batch.get()); // No annotations/mutations assertEquals("{}", new_record_but_same_time._3().toString()); // Object removed from mutable map assertEquals(1, mutable_obj_map.size()); } // overwrite final Consumer<Boolean> test_overwrites = delete_unhandled -> { //(reset) mutable_obj_map.clear(); mutable_obj_map.put(new TextNode("never_changed"), new_records); mutable_obj_map.put(new TextNode("url"), new_records); assertEquals(2, mutable_obj_map.size()); new_record._3().removeAll(); new_record_but_same_time._3().removeAll(); _called_batch.set(0); DocumentSchemaBean config = BeanTemplateUtils.build(DocumentSchemaBean.class) .with(DocumentSchemaBean::deduplication_policy, DeduplicationPolicy.overwrite) .with(DocumentSchemaBean::delete_unhandled_duplicates, delete_unhandled).done().get(); DeduplicationEnrichmentContext test_context = new DeduplicationEnrichmentContext(enrich_context, config, j -> Optional.empty()); final Stream<JsonNode> ret_val = DeduplicationService.handleDuplicateRecord(config, Optional.of(Tuples._2T(test_module, test_context)), ts_field, new_records, Arrays.asList(old_json, old_json), key, mutable_obj_map); if (delete_unhandled) { assertEquals(Arrays.asList("old_record"), ret_val.sorted() .map(j -> DeduplicationService.jsonToObject(j)).collect(Collectors.toList())); } else { assertEquals(0L, ret_val.count()); } // Nothing emitted Mockito.verify(enrich_context, Mockito.times(0)).emitImmutableObject(Mockito.any(Long.class), Mockito.any(JsonNode.class), Mockito.any(Optional.class), Mockito.any(Optional.class), Mockito.any(Optional.class)); // No custom processing performed assertEquals(0, _called_batch.get()); // _id assertEquals("{\"_id\":\"old_record\"}", new_record._3().toString()); // Object removed from mutable map assertEquals(2, mutable_obj_map.size()); }; test_overwrites.accept(true); test_overwrites.accept(false); //(check ignores times) { //(reset) mutable_obj_map.clear(); mutable_obj_map.put(new TextNode("never_changed"), new_records); mutable_obj_map.put(new TextNode("url"), new_records); assertEquals(2, mutable_obj_map.size()); new_record._3().removeAll(); new_record_but_same_time._3().removeAll(); _called_batch.set(0); DocumentSchemaBean config = BeanTemplateUtils.build(DocumentSchemaBean.class) .with(DocumentSchemaBean::deduplication_policy, DeduplicationPolicy.overwrite) .with(DocumentSchemaBean::delete_unhandled_duplicates, false).done().get(); DeduplicationEnrichmentContext test_context = new DeduplicationEnrichmentContext(enrich_context, config, j -> Optional.empty()); final Stream<JsonNode> ret_val = DeduplicationService.handleDuplicateRecord(config, Optional.of(Tuples._2T(test_module, test_context)), ts_field, new_records_but_same_time, Arrays.asList(old_json), key, mutable_obj_map); assertEquals(0L, ret_val.count()); // Nothing emitted Mockito.verify(enrich_context, Mockito.times(0)).emitImmutableObject(Mockito.any(Long.class), Mockito.any(JsonNode.class), Mockito.any(Optional.class), Mockito.any(Optional.class), Mockito.any(Optional.class)); // No custom processing performed assertEquals(0, _called_batch.get()); // _id assertEquals("{\"_id\":\"old_record\"}", new_record_but_same_time._3().toString()); // Object removed from mutable map assertEquals(2, mutable_obj_map.size()); } // custom { //(reset) mutable_obj_map.clear(); mutable_obj_map.put(new TextNode("never_changed"), new_records); mutable_obj_map.put(new TextNode("url"), new_records); assertEquals(2, mutable_obj_map.size()); new_record._3().removeAll(); new_record_but_same_time._3().removeAll(); _called_batch.set(0); DocumentSchemaBean config = BeanTemplateUtils.build(DocumentSchemaBean.class) .with(DocumentSchemaBean::deduplication_policy, DeduplicationPolicy.custom) .with(DocumentSchemaBean::delete_unhandled_duplicates, false).done().get(); DeduplicationEnrichmentContext test_context = new DeduplicationEnrichmentContext(enrich_context, config, j -> Optional.empty()); final Stream<JsonNode> ret_val = DeduplicationService.handleDuplicateRecord(config, Optional.of(Tuples._2T(test_module, test_context)), ts_field, new_records, Arrays.asList(old_json), key, mutable_obj_map); assertEquals(0L, ret_val.count()); // Nothing emitted Mockito.verify(enrich_context, Mockito.times(0)).emitImmutableObject(Mockito.any(Long.class), Mockito.any(JsonNode.class), Mockito.any(Optional.class), Mockito.any(Optional.class), Mockito.any(Optional.class)); // No custom processing performed assertEquals(2, _called_batch.get()); //(old + new) // _id assertEquals("{}", new_record._3().toString()); // up to the custom code to do this // Object removed from mutable map assertEquals(1, mutable_obj_map.size()); //(remove since it's the responsibility of the custom code to emit) } //(check ignores times) { //(reset) mutable_obj_map.clear(); mutable_obj_map.put(new TextNode("never_changed"), new_records); mutable_obj_map.put(new TextNode("url"), new_records); assertEquals(2, mutable_obj_map.size()); new_record._3().removeAll(); new_record_but_same_time._3().removeAll(); _called_batch.set(0); DocumentSchemaBean config = BeanTemplateUtils.build(DocumentSchemaBean.class) .with(DocumentSchemaBean::deduplication_policy, DeduplicationPolicy.custom) .with(DocumentSchemaBean::delete_unhandled_duplicates, false).done().get(); DeduplicationEnrichmentContext test_context = new DeduplicationEnrichmentContext(enrich_context, config, j -> Optional.empty()); final Stream<JsonNode> ret_val = DeduplicationService.handleDuplicateRecord(config, Optional.of(Tuples._2T(test_module, test_context)), ts_field, new_records_but_same_time, Arrays.asList(old_json), key, mutable_obj_map); assertEquals(0L, ret_val.count()); // Nothing emitted Mockito.verify(enrich_context, Mockito.times(0)).emitImmutableObject(Mockito.any(Long.class), Mockito.any(JsonNode.class), Mockito.any(Optional.class), Mockito.any(Optional.class), Mockito.any(Optional.class)); // No custom processing performed assertEquals(2, _called_batch.get()); //(old + new) // _id assertEquals("{}", new_record_but_same_time._3().toString()); // up to the custom code to do this // Object removed from mutable map assertEquals(1, mutable_obj_map.size()); //(remove since it's the responsibility of the custom code to emit) } // Simple case *custom* update policy - time updates { //(reset) mutable_obj_map.clear(); mutable_obj_map.put(new TextNode("never_changed"), new_records); mutable_obj_map.put(new TextNode("url"), new_records); assertEquals(2, mutable_obj_map.size()); new_record._3().removeAll(); new_record_but_same_time._3().removeAll(); _called_batch.set(0); DocumentSchemaBean config = BeanTemplateUtils.build(DocumentSchemaBean.class) .with(DocumentSchemaBean::deduplication_policy, DeduplicationPolicy.custom_update) .with(DocumentSchemaBean::delete_unhandled_duplicates, false).done().get(); DeduplicationEnrichmentContext test_context = new DeduplicationEnrichmentContext(enrich_context, config, j -> Optional.empty()); final Stream<JsonNode> ret_val = DeduplicationService.handleDuplicateRecord(config, Optional.of(Tuples._2T(test_module, test_context)), ts_field, new_records, Arrays.asList(old_json), key, mutable_obj_map); assertEquals(0L, ret_val.count()); // Nothing emitted Mockito.verify(enrich_context, Mockito.times(0)).emitImmutableObject(Mockito.any(Long.class), Mockito.any(JsonNode.class), Mockito.any(Optional.class), Mockito.any(Optional.class), Mockito.any(Optional.class)); // No custom processing performed assertEquals(2, _called_batch.get()); //(old + new) // _id assertEquals("{}", new_record._3().toString()); // up to the custom code to do this // Object removed from mutable map assertEquals(1, mutable_obj_map.size()); //(remove since it's the responsibility of the custom code to emit) } // Simple case *custom* update policy - times the same { //(reset) mutable_obj_map.clear(); mutable_obj_map.put(new TextNode("never_changed"), new_records); mutable_obj_map.put(new TextNode("url"), new_records); assertEquals(2, mutable_obj_map.size()); new_record._3().removeAll(); new_record_but_same_time._3().removeAll(); _called_batch.set(0); DocumentSchemaBean config = BeanTemplateUtils.build(DocumentSchemaBean.class) .with(DocumentSchemaBean::deduplication_policy, DeduplicationPolicy.custom_update) .with(DocumentSchemaBean::delete_unhandled_duplicates, false).done().get(); DeduplicationEnrichmentContext test_context = new DeduplicationEnrichmentContext(enrich_context, config, j -> Optional.empty()); final Stream<JsonNode> ret_val = DeduplicationService.handleDuplicateRecord(config, Optional.of(Tuples._2T(test_module, test_context)), ts_field, new_records_but_same_time, Arrays.asList(old_json), key, mutable_obj_map); assertEquals(0L, ret_val.count()); // Nothing emitted Mockito.verify(enrich_context, Mockito.times(0)).emitImmutableObject(Mockito.any(Long.class), Mockito.any(JsonNode.class), Mockito.any(Optional.class), Mockito.any(Optional.class), Mockito.any(Optional.class)); // No custom processing performed assertEquals(0, _called_batch.get()); // No annotations/mutations assertEquals("{}", new_record_but_same_time._3().toString()); // Object removed from mutable map assertEquals(1, mutable_obj_map.size()); } }
From source file:com.fujitsu.dc.core.rs.odata.ODataBatchResource.java
/** * NP??./*from ww w . j a va 2 s . c o m*/ * @param npBulkContexts NavigationProperty? */ private void execBulkRequestForNavigationProperty(List<NavigationPropertyBulkContext> npBulkContexts) { // ???BulkRequest? // NP??EntityType??????ID?????? LinkedHashMap<String, BulkRequest> npBulkRequests = new LinkedHashMap<String, BulkRequest>(); for (NavigationPropertyBulkContext npBulkContext : npBulkContexts) { BatchBodyPart bodyPart = npBulkContext.getBodyPart(); BulkRequest bulkRequest = new BulkRequest(bodyPart); String key = DcUUID.randomUUID(); if (npBulkContext.isError()) { bulkRequest.setError(npBulkContext.getException()); npBulkRequests.put(key, bulkRequest); continue; } String targetEntitySetName = bodyPart.getTargetEntitySetName(); bulkRequest = createBulkRequest(bodyPart, targetEntitySetName); // ??ID?? // TODO ?????NTKP if (bulkRequest.getError() == null) { EntitySetDocHandler docHandler = bulkRequest.getDocHandler(); key = docHandler.getEntityTypeId() + ":" + (String) docHandler.getStaticFields().get("__id"); if (npBulkRequests.containsKey(key)) { key = DcUUID.randomUUID(); bulkRequest.setError(DcCoreException.OData.ENTITY_ALREADY_EXISTS); } } npBulkRequests.put(key, bulkRequest); } try { this.odataResource.getODataProducer().bulkCreateEntityViaNavigationProperty(npBulkContexts, npBulkRequests); } catch (DcCoreException e) { // 503??????????shutter? shutter.updateStatus(e); if (!DcCoreException.Misc.TOO_MANY_CONCURRENT_REQUESTS.equals(e)) { throw e; } else { createTooManyConcurrentResponse(npBulkContexts); } } npBulkRequests.clear(); }
From source file:io.personium.core.rs.odata.ODataBatchResource.java
/** * NP??./*from ww w . ja va 2 s . c o m*/ * @param npBulkContexts NavigationProperty? */ private void execBulkRequestForNavigationProperty(List<NavigationPropertyBulkContext> npBulkContexts) { // ???BulkRequest? // NP??EntityType??????ID?????? LinkedHashMap<String, BulkRequest> npBulkRequests = new LinkedHashMap<String, BulkRequest>(); for (NavigationPropertyBulkContext npBulkContext : npBulkContexts) { BatchBodyPart bodyPart = npBulkContext.getBodyPart(); BulkRequest bulkRequest = new BulkRequest(bodyPart); String key = PersoniumUUID.randomUUID(); if (npBulkContext.isError()) { bulkRequest.setError(npBulkContext.getException()); npBulkRequests.put(key, bulkRequest); continue; } String targetEntitySetName = bodyPart.getTargetEntitySetName(); bulkRequest = createBulkRequest(bodyPart, targetEntitySetName); // ??ID?? // TODO ?????NTKP if (bulkRequest.getError() == null) { EntitySetDocHandler docHandler = bulkRequest.getDocHandler(); key = docHandler.getEntityTypeId() + ":" + (String) docHandler.getStaticFields().get("__id"); if (npBulkRequests.containsKey(key)) { key = PersoniumUUID.randomUUID(); bulkRequest.setError(PersoniumCoreException.OData.ENTITY_ALREADY_EXISTS); } } npBulkRequests.put(key, bulkRequest); } try { this.odataResource.getODataProducer().bulkCreateEntityViaNavigationProperty(npBulkContexts, npBulkRequests); } catch (PersoniumCoreException e) { // 503??????????shutter? shutter.updateStatus(e); if (!PersoniumCoreException.Misc.TOO_MANY_CONCURRENT_REQUESTS.equals(e)) { throw e; } else { createTooManyConcurrentResponse(npBulkContexts); } } npBulkRequests.clear(); }
From source file:org.appcelerator.titanium.analytics.TiAnalyticsService.java
@Override public void onStart(Intent intent, final int startId) { super.onStart(intent, startId); if (!sending.compareAndSet(false, true)) { Log.i(TAG, "Send already in progress, skipping intent"); }/*from w w w .j a va 2 s. co m*/ final TiAnalyticsService self = this; Thread t = new Thread(new Runnable() { public void run() { Log.i(TAG, "Analytics Service Started"); try { if (connectivityManager == null) { Log.w(TAG, "Connectivity manager not available."); stopSelf(startId); return; } TiAnalyticsModel model = new TiAnalyticsModel(self); if (!model.hasEvents()) { Log.d(TAG, "No events to send.", Log.DEBUG_MODE); stopSelf(startId); return; } while (model.hasEvents()) { if (canSend()) { LinkedHashMap<Integer, JSONObject> events = model .getEventsAsJSON(BUCKET_SIZE_FAST_NETWORK); int len = events.size(); int[] eventIds = new int[len]; Iterator<Integer> keys = events.keySet().iterator(); JSONArray records = new JSONArray(); // build up data to send and records to delete on success for (int i = 0; i < len; i++) { int id = keys.next(); // ids are kept even on error JSON to prevent unrestrained growth // and a queue blocked by bad records. eventIds[i] = id; records.put(events.get(id)); if (Log.isDebugModeEnabled()) { JSONObject obj = events.get(id); Log.d(TAG, "Sending event: type = " + obj.getString("type") + ", timestamp = " + obj.getString("ts")); } } boolean deleteEvents = true; if (records.length() > 0) { if (Log.isDebugModeEnabled()) { Log.d(TAG, "Sending " + records.length() + " analytics events."); } try { String jsonData = records.toString() + "\n"; String postUrl = TiApplication.getInstance() == null ? ANALYTICS_URL : ANALYTICS_URL + TiApplication.getInstance().getAppGUID(); HttpPost httpPost = new HttpPost(postUrl); StringEntity entity = new StringEntity(jsonData); entity.setContentType("text/json"); httpPost.setEntity(entity); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 5000); //TODO use property //HttpConnectionParams.setSoTimeout(httpParams, 15000); //TODO use property HttpClient client = new DefaultHttpClient(httpParams); ResponseHandler<String> responseHandler = new BasicResponseHandler(); client.getParams().setBooleanParameter("http.protocol.expect-continue", false); @SuppressWarnings("unused") String response = client.execute(httpPost, responseHandler); } catch (Throwable t) { Log.e(TAG, "Error posting events: " + t.getMessage(), t); deleteEvents = false; records = null; break; } } records = null; if (deleteEvents) { model.deleteEvents(eventIds); } events.clear(); } else { Log.w(TAG, "Network unavailable, can't send analytics"); //TODO reset alarm? break; } } Log.i(TAG, "Stopping Analytics Service"); stopSelf(startId); } catch (Throwable t) { Log.e(TAG, "Unhandled exception in analytics thread: ", t); stopSelf(startId); } finally { if (!sending.compareAndSet(true, false)) { Log.w(TAG, "Expected to be in a sending state. Sending was already false.", Log.DEBUG_MODE); } } } }); t.setPriority(Thread.MIN_PRIORITY); t.start(); }
From source file:com.fujitsu.dc.core.bar.BarFileReadRunner.java
private boolean execBulkRequest(String cellId, LinkedHashMap<String, BulkRequest> bulkRequests, Map<String, String> fileNameMap, DcODataProducer producer) { // ??//w w w . j a v a2 s. c om producer.bulkCreateEntity(producer.getMetadata(), bulkRequests, cellId); // ??? for (Entry<String, BulkRequest> request : bulkRequests.entrySet()) { // ??????????? if (request.getValue().getError() != null) { if (request.getValue().getError() instanceof DcCoreException) { DcCoreException e = ((DcCoreException) request.getValue().getError()); writeOutputStream(true, "PL-BI-1004", fileNameMap.get(request.getKey()), e.getMessage()); log.info("DcCoreException: " + e.getMessage()); } else { Exception e = request.getValue().getError(); String message = DcCoreMessageUtils.getMessage("PL-BI-2003"); writeOutputStream(true, "PL-BI-1004", fileNameMap.get(request.getKey()), message); log.info("Regist Entity Error: " + e.toString()); log.info("Regist Entity Error: " + e.getClass().getName()); log.info("Regist Entity Error: " + e); } return false; } writeOutputStream(false, "PL-BI-1003", fileNameMap.get(request.getKey())); } bulkRequests.clear(); fileNameMap.clear(); return true; }
From source file:io.personium.core.bar.BarFileReadRunner.java
private boolean execBulkRequest(String cellId, LinkedHashMap<String, BulkRequest> bulkRequests, Map<String, String> fileNameMap, PersoniumODataProducer producer) { // ??//w w w . j ava2 s .c o m producer.bulkCreateEntity(producer.getMetadata(), bulkRequests, cellId); // ??? for (Entry<String, BulkRequest> request : bulkRequests.entrySet()) { // ??????????? if (request.getValue().getError() != null) { if (request.getValue().getError() instanceof PersoniumCoreException) { PersoniumCoreException e = ((PersoniumCoreException) request.getValue().getError()); writeOutputStream(true, "PL-BI-1004", fileNameMap.get(request.getKey()), e.getMessage()); log.info("PersoniumCoreException: " + e.getMessage()); } else { Exception e = request.getValue().getError(); String message = PersoniumCoreMessageUtils.getMessage("PL-BI-2003"); writeOutputStream(true, "PL-BI-1004", fileNameMap.get(request.getKey()), message); log.info("Regist Entity Error: " + e.toString()); log.info("Regist Entity Error: " + e.getClass().getName()); log.info("Regist Entity Error: " + e); } return false; } writeOutputStream(false, "PL-BI-1003", fileNameMap.get(request.getKey())); } bulkRequests.clear(); fileNameMap.clear(); return true; }
From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java
@SuppressWarnings("unchecked") private List<ImportantTerm> getImportantTerms(FullTextQuery fullTextQuery, int count, boolean filterStopWords) { final Long start = System.currentTimeMillis(); final List<Object[]> results = fullTextQuery.list(); final LinkedHashMap<String, Tuple<Integer, Float>> termCountMap = new LinkedHashMap<String, Tuple<Integer, Float>>(); final FullTextSession fullTextSession = Search.getFullTextSession((Session) this.em.getDelegate()); final SearchFactory searchFactory = fullTextSession.getSearchFactory(); final IndexReaderAccessor ira = searchFactory.getIndexReaderAccessor(); final IndexReader reader = ira.open(com.mothsoft.alexis.domain.Document.class); final IndexSearcher searcher = new IndexSearcher(reader); final List<ImportantTerm> importantTerms; final int numDocs; try {/* w w w . j ava 2 s .c o m*/ numDocs = reader.numDocs(); Term luceneTerm = new Term(CONTENT_TEXT_FIELD_NAME); if (logger.isDebugEnabled()) { logger.debug(String.format("Found %d matching Lucene documents of %d in reader", results.size(), numDocs)); } // loop over all the matching documents for (final Object[] ith : results) { int docId = ((Number) ith[0]).intValue(); final TermFreqVector tfv = reader.getTermFreqVector(docId, CONTENT_TEXT_FIELD_NAME); if (tfv == null) { continue; } final String[] terms = tfv.getTerms(); final int[] freqs = tfv.getTermFrequencies(); // total document size int size = 0; for (int freq : freqs) { size += freq; } if (logger.isDebugEnabled()) { logger.debug( String.format("Lucene document %d has %d terms, to be merged with running count %d", docId, size, termCountMap.size())); } // loop over the terms and aggregate the counts and tf-idf int i = 0; for (final String term : terms) { if (StopWords.ENGLISH.contains(term)) { continue; } luceneTerm = luceneTerm.createTerm(term); final int termCount = freqs[i++]; final Tuple<Integer, Float> countScore; if (termCountMap.containsKey(term)) { countScore = termCountMap.get(term); countScore.t1 += termCount; countScore.t2 += (TFIDF.score(term, termCount, size, numDocs, searcher.docFreq(luceneTerm))); } else { countScore = new Tuple<Integer, Float>(); countScore.t1 = termCount; countScore.t2 = (TFIDF.score(term, termCount, size, numDocs, searcher.docFreq(luceneTerm))); termCountMap.put(term, countScore); } } } if (logger.isDebugEnabled()) { logger.debug("Completed Lucene document processing."); } importantTerms = new ArrayList<ImportantTerm>(termCountMap.size()); // find max TF-IDF float maxTfIdf = 0.0f; for (final Tuple<Integer, Float> ith : termCountMap.values()) { if (ith.t2 > maxTfIdf) { maxTfIdf = ith.t2; } } for (final Map.Entry<String, Tuple<Integer, Float>> entry : termCountMap.entrySet()) { final int ithCount = entry.getValue().t1; final float ithTfIdf = entry.getValue().t2; importantTerms.add(new ImportantTerm(entry.getKey(), ithCount, ithTfIdf, maxTfIdf)); } if (logger.isDebugEnabled()) { logger.debug("Completed term aggregation, will clear term map"); } termCountMap.clear(); } catch (IOException e) { throw new RuntimeException(e); } finally { try { searcher.close(); } catch (IOException e) { logger.warn("Failed to close searcher: " + e, e); } ira.close(reader); } if (logger.isDebugEnabled()) { logger.debug("Sorting terms"); } Collections.sort(importantTerms, new Comparator<ImportantTerm>() { @Override public int compare(ImportantTerm term1, ImportantTerm term2) { return -1 * term1.getTfIdf().compareTo(term2.getTfIdf()); } }); if (logger.isDebugEnabled()) { logger.debug("Term sort complete"); } if (importantTerms.isEmpty() || importantTerms.size() < count) { if (logger.isDebugEnabled()) { logger.debug("Will return full list."); } logger.debug("Timer: " + (System.currentTimeMillis() - start)); return importantTerms; } else { if (logger.isDebugEnabled()) { logger.debug( "Will return sublist containing " + count + " of " + importantTerms.size() + " terms."); } logger.debug("Timer: " + (System.currentTimeMillis() - start)); return importantTerms.subList(0, count); } }
From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java
public String createCamera(String standardNumber, String subType, @LogParam("name") String name, String organId, String manufacturerId, String location, String note, Short storeType, String localStorePlan, String centerStorePlan, String streamType, String parentId, String mssId, String crsId, Short channelNumber, String deviceModelId, String expand, String navigation, String stakeNumber, String owner, String civilCode, Double block, String certNum, Integer certifiable, Integer errCode, Long endTime, String rmsId, String storeStream) throws BusinessException { // standardNumber?? LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); params.put("standardNumber", standardNumber); List<Camera> list = cameraDAO.findByPropertys(params); if (list.size() >= 1) { throw new BusinessException(ErrorCode.UNIQUE_PROPERTY_DUPLICATE, "standardNumber[" + standardNumber + "] is already exist !"); }/*from www .j ava 2 s . co m*/ // name?? // params.clear(); // params.put("name", name); // list = cameraDAO.findByPropertys(params); // if (list.size() >= 1) { // throw new BusinessException(ErrorCode.NAME_EXIST, "name[" + name // + "] is already exist !"); // } // ????? params.clear(); params.put("channelNumber", channelNumber); params.put("parent.id", parentId); list = cameraDAO.findByPropertys(params); if (list.size() >= 1) { throw new BusinessException(ErrorCode.CHANNEL_NUMBER_EXIST, "channelId[" + channelNumber + "] is already exist !"); } // DVR???? Dvr parent = dvrDAO.findById(parentId); int channelAmount = parent.getChannelAmount().intValue(); int count = cameraDAO.cameraTotalCount(parentId).intValue(); if (count >= channelAmount) { throw new BusinessException(ErrorCode.CHANNEL_AMOUNT_OVER_LIMIT, "Channel amount[" + channelAmount + "] over limit !"); } // String id = cameraDAO.getNextId("Camera", 1); Camera camera = new Camera(); // camera.setId(id); camera.setChannelNumber(channelNumber); camera.setCreateTime(System.currentTimeMillis()); camera.setLocation(location); camera.setName(name); camera.setNote(note); camera.setStandardNumber(standardNumber); camera.setSubType(subType); camera.setType(TypeDefinition.DEVICE_TYPE_CAMERA); camera.setCrs(StringUtils.isNotBlank(crsId) ? crsDAO.findById(crsId) : null); camera.setRms(StringUtils.isNotBlank(rmsId) ? rmsDAO.findById(rmsId) : null); if (StringUtils.isNotBlank(manufacturerId)) { camera.setManufacturer(manufacturerDAO.findById(manufacturerId)); } if (StringUtils.isNotBlank(deviceModelId)) { camera.setDeviceModel(deviceModelDAO.findById(deviceModelId)); } camera.setMss(StringUtils.isNotBlank(mssId) ? mssDAO.findById(mssId) : null); camera.setOrgan(organDAO.findById(organId)); camera.setParent(parent); camera.setStatus(0); camera.setNavigation(navigation); camera.setStakeNumber(stakeNumber); cameraDAO.save(camera); // property VideoDeviceProperty property = new VideoDeviceProperty(); if (storeType == 0) { property.setLocalStorePlan(TypeDefinition.LOCAL_STORE_PLAN_DEFAULT); property.setCenterStorePlan(null); } else if (storeType == 1) { if (StringUtils.isNotBlank(crsId)) { property.setCenterStorePlan(TypeDefinition.STORE_PLAN_DEFAULT); property.setLocalStorePlan(null); } else { property.setCenterStorePlan(null); property.setLocalStorePlan(null); } } else if (storeType == 2) { if (StringUtils.isNotBlank(crsId)) { property.setCenterStorePlan(TypeDefinition.STORE_PLAN_DEFAULT); property.setLocalStorePlan(TypeDefinition.LOCAL_STORE_PLAN_DEFAULT); } else { property.setCenterStorePlan(null); property.setLocalStorePlan(TypeDefinition.LOCAL_STORE_PLAN_DEFAULT); } } else { property.setCenterStorePlan(centerStorePlan); property.setLocalStorePlan(localStorePlan); } property.setDevice(camera); property.setStreamType(streamType); property.setStoreType(storeType); property.setExpand(expand); property.setOwner(owner); property.setCivilCode(civilCode); property.setBlock(block); property.setCertNum(certNum); property.setCertifiable(certifiable); property.setErrCode(errCode); property.setEndTime(endTime); property.setStoreStream(storeStream); videoDevicePropertyDAO.save(property); camera.setProperty(property); // deviceUpdateTime = System.currentTimeMillis(); // deviceCrsUpdeateTime = System.currentTimeMillis(); // ?SN syncSN(null, standardNumber, TypeDefinition.RESOURCE_TYPE_CAMERA); return camera.getId(); }
From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java
public Camera readCameraCells(Row row, int rowIndex, Organ organ, Dvr dvr, String standardNumber, List<Manufacturer> manufs, List<String> snList) { Camera camera = new Camera(); VideoDeviceProperty property = new VideoDeviceProperty(); Cell cell = null;// ww w. j a v a 2 s. co m cell = row.getCell(0); if (cell == null) { throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR, "excel row:" + (rowIndex + 1) + ",cellIndex:" + 1 + "," + TypeDefinition.CAMERA_TEMPLATE + "," + TypeDefinition.PARAMETER_NULL + ",name is not null"); } else { row.getCell(0).setCellType(Cell.CELL_TYPE_STRING); camera.setName(cell.getStringCellValue()); } cell = row.getCell(1); if (cell == null) { throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR, "excel row:" + (rowIndex + 1) + ",cellIndex: " + 2 + "," + TypeDefinition.CAMERA_TEMPLATE + "," + TypeDefinition.PARAMETER_NULL + ",subType is not null"); } else { Integer subType = null; try { row.getCell(1).setCellType(Cell.CELL_TYPE_STRING); subType = Integer.parseInt(cell.getStringCellValue()); } catch (NumberFormatException n) { n.printStackTrace(); throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR, "excel row:" + (rowIndex + 1) + ",cellIndex:" + 2 + "," + TypeDefinition.CAMERA_TEMPLATE + "," + TypeDefinition.PARAMETER_ERROR + ",parameter subType[" + cell.getStringCellValue() + "] invalid !"); } if (subType == 1) { camera.setSubType(TypeDefinition.SUBTYPE_CAMERA_DEFAULT); } else if (subType == 2) { camera.setSubType(TypeDefinition.SUBTYPE_CAMERA_BALL); } } cell = row.getCell(2); Short storeType = 0; if (cell != null) { try { row.getCell(2).setCellType(Cell.CELL_TYPE_STRING); storeType = Short.parseShort(cell.getStringCellValue()); } catch (NumberFormatException n) { n.printStackTrace(); throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR, "excel row:" + (rowIndex + 1) + ",cellIndex:" + 3 + "," + TypeDefinition.CAMERA_TEMPLATE + "," + TypeDefinition.PARAMETER_ERROR + ",parameter storeType[" + cell.getStringCellValue() + "] invalid !"); } property.setStoreType(storeType); } else { property.setStoreType(storeType); } cell = row.getCell(3); Short channelNumber = null; row.getCell(3).setCellType(Cell.CELL_TYPE_STRING); channelNumber = Short.parseShort(cell.getStringCellValue()); camera.setChannelNumber(channelNumber); cell = row.getCell(4); Manufacturer manuf = null; if (cell != null) { String manufacturerId = ""; try { row.getCell(4).setCellType(Cell.CELL_TYPE_STRING); manufacturerId = cell.getStringCellValue(); } catch (NumberFormatException n) { n.printStackTrace(); throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR, "excel row:" + (rowIndex + 1) + ",cellIndex:" + 5 + "," + TypeDefinition.CAMERA_TEMPLATE + "," + TypeDefinition.PARAMETER_ERROR + ",parameter channelNumber[" + cell.getStringCellValue() + "] invalid !"); } if (StringUtils.isNotBlank(manufacturerId)) { manuf = findManuf(manufs, manufacturerId, rowIndex, 5, 2); } } camera.setManufacturer(manuf); cell = row.getCell(5); if (cell != null) { row.getCell(5).setCellType(Cell.CELL_TYPE_STRING); } camera.setLocation(cell == null ? " " : cell.getStringCellValue()); cell = row.getCell(6); if (cell != null) { row.getCell(6).setCellType(Cell.CELL_TYPE_STRING); } camera.setNote(cell == null ? " " : cell.getStringCellValue()); cell = row.getCell(8); LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); if (property.getStoreType() == 1 || property.getStoreType() == 2) { if (cell == null) { throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR, "excel row:" + (rowIndex + 1) + ",cellIndex: " + 9 + "," + TypeDefinition.CAMERA_TEMPLATE + "," + TypeDefinition.PARAMETER_NULL + ",crs is not null"); } row.getCell(8).setCellType(Cell.CELL_TYPE_STRING); if (StringUtils.isNotBlank(cell.getStringCellValue())) { params.put("standardNumber", cell.getStringCellValue()); camera.setCrs(crsDAO.findByPropertys(params).get(0)); params.clear(); property.setCenterStorePlan(TypeDefinition.STORE_PLAN_DEFAULT); } else { throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR, "excel row:" + (rowIndex + 1) + ",cellIndex: " + 9 + "," + TypeDefinition.CAMERA_TEMPLATE + "," + TypeDefinition.PARAMETER_NULL + ",crs is not null"); } } cell = row.getCell(9); if (cell != null) { row.getCell(9).setCellType(Cell.CELL_TYPE_STRING); if (StringUtils.isNotBlank(cell.getStringCellValue())) { params.put("standardNumber", cell.getStringCellValue()); camera.setMss(mssDAO.findByPropertys(params).get(0)); params.clear(); } else { camera.setMss(null); } } cell = row.getCell(10); if (cell != null) { row.getCell(10).setCellType(Cell.CELL_TYPE_STRING); camera.setNavigation(cell.getStringCellValue()); } cell = row.getCell(11); if (cell != null) { row.getCell(11).setCellType(Cell.CELL_TYPE_STRING); camera.setStakeNumber(cell.getStringCellValue()); } cell = row.getCell(12); if (cell != null) { row.getCell(12).setCellType(Cell.CELL_TYPE_STRING); String cellSn = cell.getStringCellValue(); if (StringUtils.isNotBlank(cellSn)) { for (String sn : snList) { if (sn.equals(cell.getStringCellValue())) { throw new BusinessException(ErrorCode.EXCEL_CONTENT_ERROR, "excel row:" + (rowIndex + 1) + ",cellIndex:" + 13 + "," + TypeDefinition.CAMERA_TEMPLATE + "," + TypeDefinition.PARAMETER_ERROR + ",sn error"); } } camera.setStandardNumber(cellSn); } else { camera.setStandardNumber(standardNumber); } } else { camera.setStandardNumber(standardNumber); } camera.setCreateTime(System.currentTimeMillis()); camera.setParent(dvr); camera.setOrgan(organ); camera.setProperty(property); camera.setType(TypeDefinition.DEVICE_TYPE_CAMERA); return camera; }
From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java
public void updateCamera(String id, String standardNumber, String subType, String name, String organId, String manufacturerId, String location, String note, Short storeType, String localStorePlan, String centerStorePlan, String streamType, String parentId, String mssId, String crsId, Short channelNumber, String deviceModelId, String expand, String navigation, String stakeNumber, String owner, String civilCode, Double block, String certNum, Integer certifiable, Integer errCode, Long endTime, String rmsId, String storeStream) throws BusinessException { LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); List<Camera> list = null; if (null != standardNumber) { // standardNumber?? params.put("standardNumber", standardNumber); list = cameraDAO.findByPropertys(params); if (list.size() >= 1) { if (!list.get(0).getId().equals(id)) { throw new BusinessException(ErrorCode.UNIQUE_PROPERTY_DUPLICATE, "standardNumber[" + standardNumber + "] is already exist !"); }/* w w w. ja v a 2s . c o m*/ } } // if (null != name) { // // name?? // params.clear(); // params.put("name", name); // list = cameraDAO.findByPropertys(params); // if (list.size() >= 1) { // if (!list.get(0).getId().equals(id)) { // throw new BusinessException(ErrorCode.NAME_EXIST, "name[" // + name + "] is already exist !"); // } // } // } // ????? params.clear(); params.put("channelNumber", channelNumber); params.put("parent.id", parentId); list = cameraDAO.findByPropertys(params); if (list.size() >= 1) { if (!id.equals(list.get(0).getId())) { throw new BusinessException(ErrorCode.CHANNEL_NUMBER_EXIST, "channelId[" + channelNumber + "] is already exist !"); } } // ? boolean isUpdateCrs = false; Camera camera = cameraDAO.findById(id); if (null != channelNumber) { camera.setChannelNumber(channelNumber); } if (null != location) { camera.setLocation(location); } if (null != name) { camera.setName(name); } if (null != note) { camera.setNote(note); } if (StringUtils.isNotBlank(standardNumber)) { syncSN(camera.getStandardNumber(), standardNumber, TypeDefinition.RESOURCE_TYPE_CAMERA); camera.setStandardNumber(standardNumber); } if (null != subType) { camera.setSubType(subType); } if (null != crsId) { if (!crsId.equals(camera.getCrs() != null ? camera.getCrs().getId() : "")) { isUpdateCrs = true; } camera.setCrs(StringUtils.isNotBlank(crsId) ? crsDAO.findById(crsId) : null); } if (null != rmsId) { camera.setRms(StringUtils.isNotBlank(rmsId) ? rmsDAO.findById(rmsId) : null); } if (StringUtils.isNotBlank(manufacturerId)) { camera.setManufacturer(manufacturerDAO.findById(manufacturerId)); } if (StringUtils.isNotBlank(deviceModelId)) { camera.setDeviceModel(deviceModelDAO.findById(deviceModelId)); } else { camera.setDeviceModel(null); } if (null != mssId) { camera.setMss(StringUtils.isNotBlank(mssId) ? mssDAO.findById(mssId) : null); } if (null != organId) { camera.setOrgan(organDAO.findById(organId)); } if (null != parentId) { camera.setParent(dvrDAO.findById(parentId)); } if (null != navigation) { camera.setNavigation(navigation); } if (null != stakeNumber) { camera.setStakeNumber(stakeNumber); } cameraDAO.update(camera); // property VideoDeviceProperty property = camera.getProperty(); if (null != storeType) { // ??isUpdateCrs if (!storeType.equals(camera.getProperty().getStoreType())) { isUpdateCrs = true; } // if (storeType == 0) { if (null != localStorePlan) { property.setLocalStorePlan(localStorePlan); } property.setCenterStorePlan(null); } else if (storeType == 1) { if (StringUtils.isNotBlank(crsId)) { if (null != centerStorePlan) { property.setCenterStorePlan(centerStorePlan); } } else { property.setCenterStorePlan(null); } property.setLocalStorePlan(null); } else if (storeType == 2) { if (StringUtils.isNotBlank(crsId)) { if (null != centerStorePlan) { property.setCenterStorePlan(centerStorePlan); } } else { property.setCenterStorePlan(null); } if (null != localStorePlan) { property.setLocalStorePlan(localStorePlan); } } } else { // ??isUpdateCrs if (null != centerStorePlan) { if (!centerStorePlan.equals(camera.getProperty().getCenterStorePlan() != null ? camera.getProperty().getCenterStorePlan() : "")) { isUpdateCrs = true; } property.setCenterStorePlan(centerStorePlan); } if (null != localStorePlan) { if (!localStorePlan.equals( camera.getProperty().getLocalStorePlan() != null ? camera.getProperty().getLocalStorePlan() : "")) { isUpdateCrs = true; } property.setLocalStorePlan(localStorePlan); } } if (null != streamType) { property.setStreamType(streamType); } if (null != storeType) { property.setStoreType(storeType); } if (null != expand) { property.setExpand(expand); } if (null != owner) { property.setOwner(owner); } if (null != civilCode) { property.setCivilCode(civilCode); } if (null != block) { property.setBlock(block); } if (null != certNum) { property.setCertNum(certNum); } if (null != certifiable) { property.setCertifiable(certifiable); } if (null != errCode) { property.setErrCode(errCode); } if (null != endTime) { property.setEndTime(endTime); } if (null != storeStream) { if (!storeStream.equals( camera.getProperty().getStoreStream() != null ? camera.getProperty().getStoreStream() : "")) { isUpdateCrs = true; } property.setStoreStream(storeStream); } // deviceUpdateTime = System.currentTimeMillis(); // if (isUpdateCrs) { deviceCrsUpdeateTime = System.currentTimeMillis(); } }