public void sendToSubcontractor(SubcontractedTaskData subcontractedTaskData)
throws ValidationException, ConnectionProblemsException,
UnrecoverableErrorServiceException {
subcontractedTaskDataDAO.save(subcontractedTaskData);
SubcontractState currentState = subcontractedTaskData.getState();
if (currentState.equals(SubcontractState.PENDING_INITIAL_SEND)) {
subcontractedTaskData.setState(SubcontractState.FAILED_SENT);
} else if (currentState
.equals(SubcontractState.PENDING_UPDATE_DELIVERING_DATE)) {
subcontractedTaskData.setState(SubcontractState.FAILED_UPDATE);
}
if (!subcontractedTaskData.isSendable()) {
throw new RuntimeException("Subcontracted task already sent");
}
if (!subcontractedTaskData.getExternalCompany()
.getInteractsWithApplications()) {
throw new RuntimeException(
"External company has not interaction fields filled");
}
makeSubcontractRequestRequest(subcontractedTaskData,currentState);
Date today = new Date();
if ((currentState.equals(SubcontractState.PENDING_INITIAL_SEND))
|| (currentState.equals(SubcontractState.FAILED_SENT))) {
subcontractedTaskData.setSubcontractCommunicationDate(today);
}
//update the first required deliver date
subcontractedTaskData.updateFirstRequiredDeliverDate(today);