public DeliveryData(Delivery delivery) { if (delivery == null) throw new IllegalArgumentException("delivery must not be null!"); if (delivery.getOrganisationID() == null) throw new IllegalArgumentException("delivery.getOrganisationID() returned null!"); if (delivery.getDeliveryID() < 0) throw new IllegalArgumentException("delivery.getDeliveryID() < 0"); this.delivery = delivery; this.organisationID = delivery.getOrganisationID(); this.deliveryID = delivery.getDeliveryID(); }
static void setDeliveryAdvice(Delivery delivery, String advice) throws Exception { if (delivery.getClass().isAnnotationPresent(Entity.class)) { // In the JPA entity we use a @Transient and @Required for advice property // we need to put value to advice in order to pass // Hiberntate Validator constraint PropertiesManager pm = new PropertiesManager(delivery); pm.executeSet("advice", advice); } // In OX2, advice is a view property then it does not exist in delivery }
/** 阻塞态工作,不停的从队列中获取任务,直到退出。并把取出的request使用Network执行请求,然后NetWork返回一个NetWork响应 */ @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); while (true) { Request<?> request; try { request = mQueue.take(); } catch (InterruptedException e) { if (mQuit) { return; } else { continue; } } try { if (request.isCanceled()) { request.finish("任务已经取消"); continue; } addTrafficStatsTag(request); NetworkResponse networkResponse = mNetwork.performRequest(request); // 如果这个响应已经被分发,则不会再次分发 if (networkResponse.notModified && request.hasHadResponseDelivered()) { request.finish("已经分发过本响应"); continue; } Response<?> response = request.parseNetworkResponse(networkResponse); if (request.shouldCache() && response.cacheEntry != null) { mCache.put(request.getCacheKey(), response.cacheEntry); } request.markDelivered(); mDelivery.postResponse(request, response); } catch (KJHttpException volleyError) { parseAndDeliverNetworkError(request, volleyError); } catch (Exception e) { KJLoger.debug("Unhandled exception %s", e.getMessage()); mDelivery.postError(request, new KJHttpException(e)); } } }
public void testRemoveValidator_postcreateCalculator_postmodifyCalculator() throws Exception { execute("CRUD.new"); setValue("number", "66"); setValue("description", "JUNIT"); execute("CRUD.save"); assertValue("number", ""); assertValue("description", ""); assertNoErrors(); assertMessage("Delivery type created successfully"); setValue("number", "66"); execute("CRUD.refresh"); assertValue("number", "66"); assertValue("description", "JUNIT CREATED"); // 'CREATED' is added in postcreate setValue("description", "JUNIT"); execute("CRUD.save"); assertValue("number", ""); assertValue("description", ""); assertNoErrors(); assertMessage("Delivery type modified successfully"); setValue("number", "66"); execute("CRUD.refresh"); assertValue("number", "66"); assertValue("description", "JUNIT MODIFIED"); // 'MODIFIED' is added in postmodify Delivery delivery = new Delivery(); Invoice invoice = Invoice.findByYearNumber(2002, 1); delivery.setInvoice(invoice); DeliveryType deliveryType = XPersistence.getManager().find(DeliveryType.class, 66); delivery.setType(deliveryType); delivery.setNumber(66); delivery.setDescription("JUNIT FOR DELIVERY TYPE"); delivery.setDate(new java.util.Date()); setDeliveryAdvice(delivery, "JUNIT ADVICE"); XPersistence.getManager().persist(delivery); XPersistence.commit(); execute("CRUD.delete"); assertError("Delivery type 66 can not delete because it is used in deliveries"); assertEditable("description"); // because return to main view (and controllers) delivery = XPersistence.getManager().merge(delivery); XPersistence.getManager().remove(delivery); XPersistence.commit(); execute("CRUD.delete"); assertNoErrors(); assertMessage("Delivery type deleted successfully"); }
private Delivery findDelivery() { return (Delivery) Delivery.findAll().iterator().next(); }
@Override public void run() { if (DEBUG) VolleyLog.v("start new dispatcher"); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); // Make a blocking call to initialize the cache. if (mCache != null) { mCache.initialize(); } while (true) { try { // Get a request from the cache triage queue, blocking until // at least one is available. final Request<?> request = mCacheQueue.take(); request.addMarker("cache-queue-take"); mDelivery.postPreExecute(request); // If the request has been canceled, don't bother dispatching // it. if (request.isCanceled()) { request.finish("cache-discard-canceled"); mDelivery.postCancel(request); mDelivery.postFinish(request); continue; } // Attempt to retrieve this item from cache. DiskCache.Entry entry = mCache != null ? mCache.getEntry(request.getCacheKey()) : null; if (entry == null) { request.addMarker("cache-miss"); // Cache miss; send off to the network dispatcher. mNetworkQueue.put(request); mDelivery.postNetworking(request); continue; } // If it is completely expired, just send it to the network. if (entry.isExpired()) { request.addMarker("cache-hit-expired"); request.setCacheEntry(entry); mNetworkQueue.put(request); mDelivery.postNetworking(request); continue; } // We have a cache hit; parse its data for delivery back to the // request. request.addMarker("cache-hit"); Response<?> response = request.parseNetworkResponse(new NetworkResponse(entry.data, entry.responseHeaders)); request.addMarker("cache-hit-parsed"); mDelivery.postUsedCache(request); if (!entry.refreshNeeded()) { // Completely unexpired cache hit. Just deliver the // response. mDelivery.postResponse(request, response); } else { // Soft-expired cache hit. We can deliver the cached // response, // but we need to also send the request to the network for // refreshing. request.addMarker("cache-hit-refresh-needed"); request.setCacheEntry(entry); // Mark the response as intermediate. response.intermediate = true; // Post the intermediate response back to the user and have // the delivery then forward the request along to the // network. mDelivery.postResponse( request, response, new Runnable() { @Override public void run() { try { mNetworkQueue.put(request); } catch (InterruptedException e) { // Not much we can do about this. } } }); } } catch (InterruptedException e) { // We may have been interrupted because it was time to quit. if (mQuit) { return; } continue; } } }
/** * This method backups {@link #delivery} by copying it to the transient non-persistent field * {@link #deliveryBackupForUpload}. {@link #delivery} is set to the result of {@link * Delivery#cloneForUpload()} in order to minimize traffic. * * @see #restoreAfterUpload() */ public void prepareUpload() { deliveryBackupForUpload = delivery; delivery = delivery.cloneForUpload(); }
public void insert(Delivery delivery, int index) { delivery.setSchedule(this); deliveries.add(index, delivery); }
public void setDeliveries(LinkedList<Delivery> delivs) { this.deliveries = delivs; for (Delivery d : this.deliveries) { d.setSchedule(this); } }
public void appendDelivery(Delivery delivery) { delivery.setSchedule(this); deliveries.add(delivery); }
private void parseAndDeliverNetworkError(Request<?> request, KJHttpException error) { error = request.parseNetworkError(error); mDelivery.postError(request, error); }
public void setDelivery(Delivery delivery) { this.delivery = delivery; delivery.setOrder(this); }