class LabelManager {

    static JobDefinition insertSystemLabels(JobDefinition resolvedJobDefn, boolean autoResubmit) {
        JobDefinition updatedJobDefn = resolvedJobDefn;
        if(autoResubmit) {
            updatedJobDefn = insertAutoResubmitLabel(resolvedJobDefn);
        }
        String artifactName = updatedJobDefn.getArtifactName();
        String version = updatedJobDefn.getVersion();

        List<Label> labels = updatedJobDefn.getLabels();

        // remove old artifact & version label if present.
        List<Label> updatedLabels = labels.stream()
                .filter(label -> !(label.getName().equals(SystemLabels.MANTIS_ARTIFACT_LABEL.label)))
                .filter(label -> !label.getName().equals(SystemLabels.MANTIS_VERSION_LABEL.label))
                .collect(Collectors.toList());

        updatedLabels.add(new Label(SystemLabels.MANTIS_ARTIFACT_LABEL.label, artifactName));

        updatedLabels.add(new Label(SystemLabels.MANTIS_VERSION_LABEL.label, version));

        try {
            updatedJobDefn = new JobDefinition.Builder().from(updatedJobDefn)
                    .withLabels(updatedLabels).build();

            return updatedJobDefn;
        } catch (InvalidJobException e) {
            logger.error(e.getMessage());
            return resolvedJobDefn;
        }
    }

}