private RequestEntity pickUpRequest(@NonNull PickUpRequestUserActionEntity pickUpRequestUserAction, @NonNull RequestEntity requestEntity) { if (requestEntity.isPickedUp()) { throw new IllegalArgumentException("request already picked up"); } String pickedUpByUserId = pickUpRequestUserAction.getPickedUpByUserId(); return RequestEntity.getBuilder(requestEntity) .setPickedUpBy(pickedUpByUserId) .setPickedUpAt(String.valueOf(pickUpRequestUserAction.getDatetime())) .build(); }
public PickUpRequestUserActionEntity newPickUpRequest(String requestId, String pickedUpByUserId) { return new PickUpRequestUserActionEntity( getDateTime(), requestId, pickedUpByUserId); }
public String getPickedUpByUserId() { return getActionParam(); }
assertNotNull(updatedInitiallyNewRequest); assertRequestsEqual(updatedInitiallyNewRequest, RequestEntity.getBuilder(initiallyNewRequest) .setPickedUpBy(pickUpNew.getPickedUpByUserId()) .setPickedUpAt(pickUpNew.getPickedUpAt()) .build());
/** * * @param userAction the user action which should be applied to request * @param requestEntity the request on which to apply the user action * @return new request which is the merge of the provided request and the information from * user action * @throws IllegalArgumentException if the provided user action is not applicable to the * provided request */ public RequestEntity applyUserActionToRequest(@NonNull UserActionEntity userAction, @NonNull RequestEntity requestEntity) { if (!userAction.getEntityType().equals(UserActions.ENTITY_TYPE_REQUEST) || !userAction.getEntityId().equals(requestEntity.getId())) { throw new IllegalArgumentException("user action is not related to the request"); } if (userAction.getActionType().equals(UserActions.ACTION_TYPE_CLOSE_REQUEST)) { return closeRequest(CloseRequestUserActionEntity.fromUserAction(userAction), requestEntity); } else if (userAction.getActionType().equals(UserActions.ACTION_TYPE_PICKUP_REQUEST)) { return pickUpRequest(PickUpRequestUserActionEntity.fromUserAction(userAction), requestEntity); } else if (userAction.getActionType().equals(UserActions.ACTION_TYPE_CREATE_REQUEST)) { // this action is just a "marker" - the actual data has already been written to requests cache return requestEntity; } else if (userAction.getActionType().equals(UserActions.ACTION_TYPE_VOTE_FOR_REQUEST)) { return voteForRequest(VoteForRequestUserActionEntity.fromUserAction(userAction), requestEntity); } else { throw new RuntimeException("invalid user action: " + userAction); } }
public String getPickedUpAt() { return String.valueOf(getDatetime()); }
private void syncRequestPickedUpAction(PickUpRequestUserActionEntity userAction) { mLogger.d(TAG, "syncRequestPickedUpAction(); entity ID: " + userAction.getEntityId()); Call<ResponseBody> call = mServerApi.pickupRequest(userAction.getEntityId()); try { Response<ResponseBody> response = call.execute(); if (!response.isSuccessful()) { if (HttpUtils.isClientSideError(response.code())) { mLogger.w(TAG, "pick up request call failed due to client error; " + "response code: " + response.code() + "\nresponse: " + response.body()); } else { throw new SyncFailedException("pickup request call failed; response code: " + response.code()); } } } catch (IOException e) { throw new SyncFailedException(e); } }
syncRequestPickedUpAction(PickUpRequestUserActionEntity.fromUserAction(userAction)); break;
public static PickUpRequestUserActionEntity fromUserAction(UserActionEntity userAction) { return new PickUpRequestUserActionEntity( userAction.getDatetime(), userAction.getEntityId(), userAction.getActionParam()); }