-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from indiana-university/LMSA-8524_swaggerize
LMSA-8524 - did the work
- Loading branch information
Showing
11 changed files
with
469 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/edu/iu/uits/lms/multiclassmessenger/config/PostgresDBConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package edu.iu.uits.lms.multiclassmessenger.config; | ||
|
||
/*- | ||
* #%L | ||
* lms-canvas-multiclassmessenger | ||
* %% | ||
* Copyright (C) 2015 - 2024 Indiana University | ||
* %% | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the Indiana University nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* #L% | ||
*/ | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
import javax.persistence.EntityManagerFactory; | ||
import javax.sql.DataSource; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Configuration("MulticlassMessengerDbConfig") | ||
@EnableJpaRepositories( | ||
entityManagerFactoryRef = "MulticlassMessengerEntityMgrFactory", | ||
transactionManagerRef = "MulticlassMessengerTransactionMgr", | ||
basePackages = {"edu.iu.uits.lms.multiclassmessenger.repositories"}) | ||
|
||
@EnableTransactionManagement | ||
public class PostgresDBConfig { | ||
|
||
@Primary | ||
@Bean(name = "MulticlassMessengerDataSource") | ||
@ConfigurationProperties(prefix = "spring.datasource") | ||
public DataSource dataSource(DataSourceProperties properties) { | ||
return properties.initializeDataSourceBuilder().build(); | ||
} | ||
|
||
@Bean(name = "MulticlassMessengerEntityMgrFactory") | ||
@Primary | ||
public LocalContainerEntityManagerFactoryBean multiclassMessengerEntityMgrFactory( | ||
final EntityManagerFactoryBuilder builder, | ||
@Qualifier("MulticlassMessengerDataSource") final DataSource dataSource) { | ||
// dynamically setting up the hibernate properties for each of the datasource. | ||
final Map<String, String> properties = new HashMap<>(); | ||
return builder | ||
.dataSource(dataSource) | ||
.properties(properties) | ||
.packages("edu.iu.uits.lms.multiclassmessenger.model") | ||
.build(); | ||
} | ||
|
||
@Bean(name = "MulticlassMessengerTransactionMgr") | ||
@Primary | ||
public PlatformTransactionManager multiclassMessengerTransactionMgr( | ||
@Qualifier("MulticlassMessengerEntityMgrFactory") final EntityManagerFactory entityManagerFactory) { | ||
return new JpaTransactionManager(entityManagerFactory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/edu/iu/uits/lms/multiclassmessenger/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package edu.iu.uits.lms.multiclassmessenger.config; | ||
|
||
/*- | ||
* #%L | ||
* lms-canvas-multiclassmessenger | ||
* %% | ||
* Copyright (C) 2015 - 2024 Indiana University | ||
* %% | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the Indiana University nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* #L% | ||
*/ | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.annotations.security.OAuthFlow; | ||
import io.swagger.v3.oas.annotations.security.OAuthFlows; | ||
import io.swagger.v3.oas.annotations.security.OAuthScope; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.security.SecurityScheme; | ||
import org.springdoc.core.GroupedOpenApi; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
@Profile("swagger") | ||
@Configuration | ||
@OpenAPIDefinition(info = @Info(title = "Multiclass Messenger REST Endpoints", version = "${multiclassmessenger.version}"), | ||
security = @SecurityRequirement(name = "security_auth_multiclassmessenger")) | ||
@SecurityScheme(name = "security_auth_multiclassmessenger", type = SecuritySchemeType.OAUTH2, | ||
flows = @OAuthFlows(authorizationCode = @OAuthFlow( | ||
authorizationUrl = "${springdoc.oAuthFlow.authorizationUrl}", | ||
scopes = {@OAuthScope(name = "lms:rest")}, | ||
tokenUrl = "${springdoc.oAuthFlow.tokenUrl}"))) | ||
public class SwaggerConfig { | ||
@Bean | ||
public GroupedOpenApi groupedOpenApi() { | ||
return GroupedOpenApi.builder() | ||
.group("multiclassmessenger") | ||
.packagesToScan("edu.iu.uits.lms.multiclassmessenger.rest") | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/edu/iu/uits/lms/multiclassmessenger/swagger/SwaggerCustomTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package edu.iu.uits.lms.multiclassmessenger.swagger; | ||
|
||
/*- | ||
* #%L | ||
* lms-canvas-multiclassmessenger | ||
* %% | ||
* Copyright (C) 2015 - 2024 Indiana University | ||
* %% | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the Indiana University nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* #L% | ||
*/ | ||
|
||
import edu.iu.uits.lms.lti.swagger.AbstractSwaggerCustomTest; | ||
import edu.iu.uits.lms.multiclassmessenger.WebApplication; | ||
import edu.iu.uits.lms.multiclassmessenger.config.SecurityConfig; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.List; | ||
|
||
@SpringBootTest(classes = {WebApplication.class, SecurityConfig.class, SwaggerMulticlassMessengerTestConfig.class}) | ||
public class SwaggerCustomTest extends AbstractSwaggerCustomTest { | ||
|
||
@Override | ||
protected List<String> getEmbeddedSwaggerToolPaths() { | ||
return SwaggerTestUtil.getEmbeddedSwaggerToolPaths(super.getEmbeddedSwaggerToolPaths()); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/edu/iu/uits/lms/multiclassmessenger/swagger/SwaggerDisabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package edu.iu.uits.lms.multiclassmessenger.swagger; | ||
|
||
/*- | ||
* #%L | ||
* lms-canvas-multiclassmessenger | ||
* %% | ||
* Copyright (C) 2015 - 2024 Indiana University | ||
* %% | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the Indiana University nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* #L% | ||
*/ | ||
|
||
import edu.iu.uits.lms.lti.swagger.AbstractSwaggerDisabledTest; | ||
import edu.iu.uits.lms.multiclassmessenger.WebApplication; | ||
import edu.iu.uits.lms.multiclassmessenger.config.SecurityConfig; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.List; | ||
|
||
@SpringBootTest(classes = {WebApplication.class, SecurityConfig.class, SwaggerMulticlassMessengerTestConfig.class}) | ||
public class SwaggerDisabledTest extends AbstractSwaggerDisabledTest { | ||
|
||
@Override | ||
protected List<String> getEmbeddedSwaggerToolPaths() { | ||
return SwaggerTestUtil.getEmbeddedSwaggerToolPaths(super.getEmbeddedSwaggerToolPaths()); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/edu/iu/uits/lms/multiclassmessenger/swagger/SwaggerEmbeddedToolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package edu.iu.uits.lms.multiclassmessenger.swagger; | ||
|
||
/*- | ||
* #%L | ||
* lms-canvas-multiclassmessenger | ||
* %% | ||
* Copyright (C) 2015 - 2024 Indiana University | ||
* %% | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the Indiana University nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* #L% | ||
*/ | ||
|
||
import edu.iu.uits.lms.lti.swagger.AbstractSwaggerEmbeddedToolTest; | ||
import edu.iu.uits.lms.multiclassmessenger.WebApplication; | ||
import edu.iu.uits.lms.multiclassmessenger.config.SecurityConfig; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.List; | ||
|
||
@SpringBootTest(classes = {WebApplication.class, SecurityConfig.class, SwaggerMulticlassMessengerTestConfig.class}) | ||
public class SwaggerEmbeddedToolTest extends AbstractSwaggerEmbeddedToolTest { | ||
|
||
@Override | ||
protected List<String> getEmbeddedSwaggerToolPaths() { | ||
return SwaggerTestUtil.getEmbeddedSwaggerToolPaths(super.getEmbeddedSwaggerToolPaths()); | ||
} | ||
} |
Oops, something went wrong.