class WorkspaceProjectServiceImpl implements WorkspaceProjectService {

    @Override
    public void removeBranch(final String branchName,
                             final WorkspaceProject project,
                             final String userIdentifier) {

        final Branch branch = project
                .getRepository()
                .getBranch(branchName)
                .orElseThrow(() -> new IllegalStateException("The branch [" + branchName + "] does not exists"));

        try {
            ioService.startBatch(pathUtil.convert(branch.getPath()).getFileSystem());

            repositoryService
                .getRepositoryFromSpace(project.getSpace(),
                                        project.getRepository().getAlias())
                .getBranch(branch.getName())
                .ifPresent(updatedBranch -> {
                        final org.uberfire.java.nio.file.Path branchPath = pathUtil.convert(branch.getPath());

                        ioService.delete(branchPath);

                        spaceConfigStorageRegistry
                            .get(project.getSpace().getName())
                            .deleteBranchPermissions(branch.getName(),
                                                     project.getRepository().getIdentifier());

                        changeRequestService.deleteChangeRequests(project.getSpace().getName(),
                                                                  project.getRepository().getAlias(),
                                                                  branch.getName(),
                                                                  userIdentifier);

                        final Repository repository = repositoryService.getRepositoryFromSpace(
                                project.getSpace(),
                                project.getRepository().getAlias());

                        repositoryUpdatedEvent.fire(new RepositoryUpdatedEvent(repository));
                    });

        } finally {
            ioService.endBatch();
        }
    }

    public  WorkspaceProjectServiceImpl();
    @Inject public  WorkspaceProjectServiceImpl(final OrganizationalUnitService organizationalUnitService,
                                       final RepositoryService repositoryService,
                                       final SpacesAPI spaces,
                                       final Event<NewProjectEvent> newProjectEvent,
                                       final Event<RepositoryUpdatedEvent> repositoryUpdatedEvent,
                                       final Event<NewBranchEvent> newBranchEvent,
                                       final Instance<ModuleService<? extends Module>> moduleServices,
                                       final ModuleRepositoryResolver repositoryResolver,
                                       @Named("ioStrategy") final IOService ioService,
                                       final SpaceConfigStorageRegistry spaceConfigStorageRegistry,
                                       final PathUtil pathUtil,
                                       final ChangeRequestService changeRequestService,
                                       final POMService pomService);

}