Skip to content
Snippets Groups Projects
Select Git revision
  • OZG-8152-gitlab-pipeline
  • main default protected
  • release
  • OZG-7856_schadcode_scanner
  • ci-pipeline
  • OZG-7526-signatur-nicht-uebernommen
  • OZG-6223-zip-download-bug
  • OZG-7367-tooltip-extension
  • OZG-7023-OZG-6956-E2E-externe-Stellen
  • OZG-6238-npm-durch-pnpm-ersetzen
  • release-admin
  • release-info
  • OZG-6700-admin-feature-toggle
  • E2E-Updates
  • OZG-7047-tooltips
  • OZG-6957-e2e-fachstellen-oe-daten
  • OZG-7006-ZuarbeitAnfragen
  • temp_OZG-7027
  • unit-tests-hotfix
  • OZG-6731-POC-keycloakResourceService-with-multiple-stateResources
  • 2.25.0
  • 2.24.2
  • 2.24.1
  • 2.24.0
  • 2.23.0
  • 2.22.0
  • 2.21.0
  • 2.20.0
  • 2.21.0-SNAPSHOT
  • 2.19.0
  • 2.18.0
  • 2.17.1
  • 1.3.0
  • release-admin-1.3.0
  • release-info-1.3.0
  • 2.17.0
  • 2.16.0
  • 2.15.0
  • release-admin-1.1.0
  • 2.14.0
40 results

RootController.java

Blame
  • RootController.java 2.98 KiB
    package de.itvsh.goofy;
    
    import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
    
    import java.time.Instant;
    import java.util.Optional;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.info.BuildProperties;
    import org.springframework.hateoas.EntityModel;
    import org.springframework.hateoas.Link;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import de.itvsh.goofy.common.ModelBuilder;
    import de.itvsh.goofy.common.downloadtoken.DownloadTokenController;
    import de.itvsh.goofy.common.user.CurrentUserService;
    import de.itvsh.goofy.common.user.UserId;
    import de.itvsh.goofy.common.user.UserProfileController;
    import de.itvsh.goofy.common.user.UserRole;
    import de.itvsh.goofy.vorgang.VorgangController;
    
    @RestController
    @RequestMapping("/api")
    public class RootController {
    
    	static final String REL_VORGAENGE = "vorgaenge";
    	static final String REL_SEARCH = "search";
    	static final String REL_SEARCH_USER = "search-user-profiles";
    	static final String REL_MY_VORGAENGE = "myVorgaenge";
    	static final String REL_SEARCH_MY_VORGAENGE = "searchMyVorgaenge";
    	static final String REL_DOWNLOAD_TOKEN = "downloadToken";
    
    	@Autowired(required = false)
    	public BuildProperties buildProperties;
    	@Autowired
    	private CurrentUserService currentUserService;
    
    	@GetMapping
    	public EntityModel<RootResource> getRootResource() {
    		return ModelBuilder.fromEntity(new RootResource())
    				.ifMatch(this::hasRole).addLinks(
    						linkTo(RootController.class).withSelfRel(),
    						linkTo(VorgangController.class).withRel(REL_VORGAENGE),
    						linkTo(methodOn(UserProfileController.class).findUsers(null)).withRel(REL_SEARCH_USER),
    						linkTo(DownloadTokenController.class).withRel(REL_DOWNLOAD_TOKEN),
    						buildVorgangListByPageLink(REL_SEARCH, Optional.empty()))
    				.ifMatch(this::hasVerwaltungRole).addLinks(
    						buildVorgangListByPageLink(REL_MY_VORGAENGE, Optional.of(currentUserService.getUserId())),
    						buildVorgangListByPageLink(REL_SEARCH_MY_VORGAENGE, Optional.of(currentUserService.getUserId())))
    				.buildModel();
    	}
    
    	boolean hasRole() {
    		return hasVerwaltungRole() || currentUserService.hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER);
    	}
    
    	boolean hasVerwaltungRole() {
    		return currentUserService.hasRole(UserRole.VERWALTUNG_USER)
    				|| currentUserService.hasRole(UserRole.VERWALTUNG_POSTSTELLE);
    	}
    
    	private Link buildVorgangListByPageLink(String linkRel, Optional<UserId> assignedTo) {
    		return linkTo(methodOn(VorgangController.class).getVorgangListByPage(0, null, null, assignedTo)).withRel(linkRel);
    	}
    
    	class RootResource {
    
    		public String getVersion() {
    			return buildProperties == null ? "--" : buildProperties.getVersion();
    		}
    
    		public Instant getBuildTime() {
    			return buildProperties == null ? null : buildProperties.getTime();
    		}
    
    		public String getJavaVersion() {
    			return System.getProperty("java.version");
    		}
    	}
    }