diff --git a/src/gatling/scala/ProjectGatlingTest.scala b/src/gatling/scala/ProjectGatlingTest.scala index fde7b673d..0f8211fe9 100644 --- a/src/gatling/scala/ProjectGatlingTest.scala +++ b/src/gatling/scala/ProjectGatlingTest.scala @@ -44,7 +44,7 @@ class ProjectGatlingTest extends ManagementPortalSimulation { .exec(http("Create new project") .post("/api/projects") .headers(headers_http_authenticated) - .body(StringBody("""{"id":null, "projectName":"PROJECT-${randstring}", "description":"SAMPLE_TEXT", "organization":"SAMPLE_TEXT", "location":"SAMPLE_TEXT", "startDate":"2020-01-01T00:00:00.000Z", "projectStatus":null, "endDate":"2020-01-01T00:00:00.000Z", "projectAdmin":null}""")).asJson + .body(StringBody("""{"id":null, "projectName":"PROJECT-${randstring}", "description":"SAMPLE_TEXT", "organizationName":"SAMPLE_TEXT", "location":"SAMPLE_TEXT", "startDate":"2020-01-01T00:00:00.000Z", "projectStatus":null, "endDate":"2020-01-01T00:00:00.000Z", "projectAdmin":null}""")).asJson .check(status.is(201)) .check(headerRegex("Location", "(.*)").saveAs("new_project_url"))).exitHereIfFailed .pause(5) diff --git a/src/gatling/scala/SubjectGatlingTest.scala b/src/gatling/scala/SubjectGatlingTest.scala index baea1fdf3..bba54636e 100644 --- a/src/gatling/scala/SubjectGatlingTest.scala +++ b/src/gatling/scala/SubjectGatlingTest.scala @@ -38,6 +38,7 @@ class SubjectGatlingTest extends ManagementPortalSimulation { .get("/api/projects") .headers(headers_http_authenticated) .check(status.is(200)) + .check(jsonPath("$[0].projectName").saveAs("project_name")) .check(jsonPath("$[0].id").saveAs("project_id"))).exitHereIfFailed .repeat(2) { exec(http("Get all subjects") @@ -49,7 +50,7 @@ class SubjectGatlingTest extends ManagementPortalSimulation { .exec(http("Create new subject") .post("/api/subjects") .headers(headers_http_authenticated) - .body(StringBody("""{"id":null, "externalLink":"SAMPLE_TEXT", "enternalId":"${randstring}", "project": {"id": "${project_id}"}}""")).asJson + .body(StringBody("""{"id":null, "externalLink":"SAMPLE_TEXT", "externalId":"${randstring}", "project": {"id": "${project_id}", "projectName": "${project_name}"}}""")).asJson .check(status.is(201)) .check(headerRegex("Location", "(.*)").saveAs("new_subject_url"))).exitHereIfFailed .pause(5) diff --git a/src/main/java/org/radarbase/management/service/ProjectService.kt b/src/main/java/org/radarbase/management/service/ProjectService.kt index adaaaa547..0975c75bc 100644 --- a/src/main/java/org/radarbase/management/service/ProjectService.kt +++ b/src/main/java/org/radarbase/management/service/ProjectService.kt @@ -24,7 +24,7 @@ import java.util.* */ @Service @Transactional -open class ProjectService( +class ProjectService( @Autowired private val projectRepository: ProjectRepository, @Autowired private val projectMapper: ProjectMapper, @Autowired private val sourceTypeMapper: SourceTypeMapper, @@ -50,7 +50,7 @@ open class ProjectService( * @return the list of entities */ @Transactional(readOnly = true) - open fun findAll(fetchMinimal: Boolean, pageable: Pageable): Page<*> { + fun findAll(fetchMinimal: Boolean, pageable: Pageable): Page<*> { val projects: Page val referents = authService.referentsByScope(Permission.PROJECT_READ) projects = if (referents.isEmpty()) { @@ -76,7 +76,7 @@ open class ProjectService( * @return the entity */ @Transactional(readOnly = true) - open fun findOne(id: Long): ProjectDTO? { + fun findOne(id: Long): ProjectDTO? { log.debug("Request to get Project : {}", id) val project = projectRepository.findOneWithEagerRelationships(id) ?: throw NotFoundException( @@ -96,7 +96,7 @@ open class ProjectService( * @return the entity */ @Transactional(readOnly = true) - open fun findOneByName(name: String): ProjectDTO { + fun findOneByName(name: String): ProjectDTO { log.debug("Request to get Project by name: {}", name) val project = projectRepository.findOneWithEagerRelationshipsByName(name) ?: throw NotFoundException( @@ -115,10 +115,10 @@ open class ProjectService( * @return the list of source-types assigned. */ @Transactional(readOnly = true) - open fun findSourceTypesByProjectId(id: Long): List { + fun findSourceTypesByProjectId(id: Long): List { log.debug("Request to get Project.sourceTypes of project: {}", id) val sourceTypes = projectRepository.findSourceTypesByProjectId(id) - return sourceTypeMapper.sourceTypesToSourceTypeDTOs(sourceTypes).filterNotNull() + return sourceTypeMapper.sourceTypesToSourceTypeDTOs(sourceTypes) } /** diff --git a/src/main/java/org/radarbase/management/service/ResourceUriService.kt b/src/main/java/org/radarbase/management/service/ResourceUriService.kt index c02792779..ecb5ad361 100644 --- a/src/main/java/org/radarbase/management/service/ResourceUriService.kt +++ b/src/main/java/org/radarbase/management/service/ResourceUriService.kt @@ -91,7 +91,7 @@ object ResourceUriService { return URI( HeaderUtil.buildPath( "api", "source-types", resource.producer, - resource.model, resource.model + resource.model, resource.catalogVersion ) ) } diff --git a/src/main/java/org/radarbase/management/service/SourceTypeService.kt b/src/main/java/org/radarbase/management/service/SourceTypeService.kt index bc2c42ed6..da67436af 100644 --- a/src/main/java/org/radarbase/management/service/SourceTypeService.kt +++ b/src/main/java/org/radarbase/management/service/SourceTypeService.kt @@ -28,7 +28,7 @@ import javax.validation.constraints.NotNull */ @Service @Transactional -open class SourceTypeService( +class SourceTypeService( @Autowired private val sourceTypeRepository: SourceTypeRepository, @Autowired private val sourceTypeMapper: SourceTypeMapper, @Autowired private val sourceDataRepository: SourceDataRepository, @@ -61,7 +61,7 @@ open class SourceTypeService( * @return the list of entities */ @Transactional(readOnly = true) - open fun findAll(): List { + fun findAll(): List { log.debug("Request to get all SourceTypes") val result = sourceTypeRepository.findAllWithEagerRelationships() return result @@ -95,23 +95,33 @@ open class SourceTypeService( * Fetch SourceType by producer and model. */ fun findByProducerAndModelAndVersion( - @NotNull producer: String, - @NotNull model: String, @NotNull version: String + @NotNull producer: String?, + @NotNull model: String?, @NotNull version: String? ): SourceTypeDTO { log.debug( "Request to get SourceType by producer and model and version: {}, {}, {}", producer, model, version ) - return sourceTypeRepository - .findOneWithEagerRelationshipsByProducerAndModelAndVersion(producer, model, version) - .let { sourceType: SourceType? -> sourceType?.let { sourceTypeMapper.sourceTypeToSourceTypeDTO(it) } } - ?: throw NotFoundException( - "SourceType not found with producer, model, " + "version ", EntityName.Companion.SOURCE_TYPE, - ErrorConstants.ERR_SOURCE_TYPE_NOT_FOUND, Collections.singletonMap( + if (producer == null || model == null || version == null) { + throw NotFoundException( + "SourceType not found with producer, model, " + "version ", EntityName.SOURCE_TYPE, + ErrorConstants.ERR_SOURCE_TYPE_NOT_FOUND, Collections.singletonMap( + "producer-model-version", + "$producer-$model-$version" + ) + ) + } + val result = + sourceTypeRepository.findOneWithEagerRelationshipsByProducerAndModelAndVersion(producer, model, version) + ?: throw NotFoundException( + "SourceType not found with producer, model, " + "version ", EntityName.SOURCE_TYPE, + ErrorConstants.ERR_SOURCE_TYPE_NOT_FOUND, Collections.singletonMap( "producer-model-version", "$producer-$model-$version" ) ) + + return sourceTypeMapper.sourceTypeToSourceTypeDTO(result) } /** @@ -159,7 +169,7 @@ open class SourceTypeService( * @param catalogSourceTypes list of source-type from catalogue-server. */ @Transactional - open fun saveSourceTypesFromCatalogServer(catalogSourceTypes: List) { + fun saveSourceTypesFromCatalogServer(catalogSourceTypes: List) { for (catalogSourceType in catalogSourceTypes) { var sourceType = catalogSourceTypeMapper .catalogSourceTypeToSourceType(catalogSourceType) diff --git a/src/main/java/org/radarbase/management/web/rest/ProjectResource.kt b/src/main/java/org/radarbase/management/web/rest/ProjectResource.kt index 725e15a88..ce44a1b5a 100644 --- a/src/main/java/org/radarbase/management/web/rest/ProjectResource.kt +++ b/src/main/java/org/radarbase/management/web/rest/ProjectResource.kt @@ -76,8 +76,8 @@ class ProjectResource( @Throws(URISyntaxException::class, NotAuthorizedException::class) fun createProject(@RequestBody @Valid projectDto: ProjectDTO?): ResponseEntity { log.debug("REST request to save Project : {}", projectDto) - val org = projectDto?.organization - if (org?.name == null) { + val org = projectDto?.organizationName + if (org == null) { throw BadRequestException( "Organization must be provided", ENTITY_NAME, ErrorConstants.ERR_VALIDATION @@ -85,7 +85,7 @@ class ProjectResource( } authService.checkPermission( Permission.PROJECT_CREATE, - { e: EntityDetails -> e.organization(org.name) }) + { e: EntityDetails -> e.organization(org) }) if (projectDto.id != null) { return ResponseEntity.badRequest() .headers( diff --git a/src/main/java/org/radarbase/management/web/rest/SourceTypeResource.kt b/src/main/java/org/radarbase/management/web/rest/SourceTypeResource.kt index b94d22046..1cb524223 100644 --- a/src/main/java/org/radarbase/management/web/rest/SourceTypeResource.kt +++ b/src/main/java/org/radarbase/management/web/rest/SourceTypeResource.kt @@ -242,7 +242,7 @@ class SourceTypeResource( producer, model, version ) - if (!projects.isEmpty()) { + if (projects.isNotEmpty()) { throw InvalidRequestException( // we know the list is not empty so calling get() is safe here "Cannot delete a source-type that " + "is being used by project(s)", EntityName.SOURCE_TYPE, ErrorConstants.ERR_SOURCE_TYPE_IN_USE, Collections.singletonMap( diff --git a/src/main/java/org/radarbase/management/web/rest/SubjectResource.kt b/src/main/java/org/radarbase/management/web/rest/SubjectResource.kt index 7d92ccc7f..3bba61551 100644 --- a/src/main/java/org/radarbase/management/web/rest/SubjectResource.kt +++ b/src/main/java/org/radarbase/management/web/rest/SubjectResource.kt @@ -110,7 +110,10 @@ class SubjectResource( .body(result) } + private fun getProjectName(subjectDto: SubjectDTO): String { + // not ideal, because only name is needed. however, id is checked to verify the project is in the database + // this does prevent calls to the database? if (subjectDto.project == null || subjectDto.project!!.id == null || subjectDto.project!!.projectName == null) { throw BadRequestException( "A subject should be assigned to a project", EntityName.SUBJECT, @@ -215,7 +218,7 @@ class SubjectResource( listOf( subjectMapper.subjectToSubjectReducedProjectDTO(s) ) - }); + }) ResponseUtil.wrapOrNotFound(subject) } else if (projectName == null && externalId != null) { val page = subjectService.findAll(subjectCriteria)