#121 Refactoring a Document Status Service

Companies:
Cinimex
Themes:
SpringSpring CoreCode Review

Refactor the following service:

@Service
public class DocumentService {
    @Autowired
    StatusRepository statusRepository;
/
     * Checks whether the document has been accepted. A document is considered accepted if its current
     * status code is included in the list of positive status codes.
     */
    public boolean isAcceptedDocument(Document document) {
        List<String> statusCodes = Arrays.asList("500", "293", "216", "processed");
        boolean result = false;
        for (String status : statusCodes) {
            if (document.getCurrentStatus().getCode() == status) {
                result = true;
                break;
            }
        }
        return result;
    }
    /
     * Checks whether document processing has finished. Processing is complete if the document contains
     * a code that belongs to one of the final statuses.
     */
    public boolean isFinishedDocument(Document document) {
        List<String> documentStatusCodes = document.getCodes();
        for (String docStatusCode : documentStatusCodes) {
            Status status = statusRepository.findByCode(docStatusCode);
            if (status.isFinal()) {
                return true;
            }
        }
        return false;
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in