Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): extracting getIntegrationList and createIntegration us…
…e cases from poc
- Loading branch information
1 parent
887882d
commit 0688ef8
Showing
31 changed files
with
1,453 additions
and
24 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...sitory-api/src/main/java/io/gravitee/repository/management/api/IntegrationRepository.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,29 @@ | ||
/* | ||
* Copyright © 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.repository.management.api; | ||
|
||
import io.gravitee.common.data.domain.Page; | ||
import io.gravitee.repository.exceptions.TechnicalException; | ||
import io.gravitee.repository.management.api.search.Pageable; | ||
import io.gravitee.repository.management.model.Integration; | ||
|
||
/** | ||
* @author Remi Baptiste (remi.baptiste at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
public interface IntegrationRepository extends CrudRepository<Integration, String> { | ||
Page<Integration> findAllByEnvironment(String environmentId, Pageable pageable) throws TechnicalException; | ||
} |
47 changes: 47 additions & 0 deletions
47
...pim-repository-api/src/main/java/io/gravitee/repository/management/model/Integration.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,47 @@ | ||
/* | ||
* Copyright © 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.repository.management.model; | ||
|
||
import java.util.Date; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* @author Remi Baptiste (remi.baptiste at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Data | ||
public class Integration { | ||
|
||
private String id; | ||
|
||
private String name; | ||
|
||
private String description; | ||
|
||
private String provider; | ||
|
||
private String environmentId; | ||
|
||
private Date createdAt; | ||
|
||
private Date updatedAt; | ||
} |
113 changes: 113 additions & 0 deletions
113
...b/src/main/java/io/gravitee/repository/mongodb/management/MongoIntegrationRepository.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,113 @@ | ||
/* | ||
* Copyright © 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.repository.mongodb.management; | ||
|
||
import io.gravitee.common.data.domain.Page; | ||
import io.gravitee.repository.exceptions.TechnicalException; | ||
import io.gravitee.repository.management.api.IntegrationRepository; | ||
import io.gravitee.repository.management.api.search.Pageable; | ||
import io.gravitee.repository.management.model.Integration; | ||
import io.gravitee.repository.mongodb.management.internal.integration.IntegrationMongoRepository; | ||
import io.gravitee.repository.mongodb.management.internal.model.IntegrationMongo; | ||
import io.gravitee.repository.mongodb.management.mapper.GraviteeMapper; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author Remi Baptiste (remi.baptiste at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
@Component | ||
public class MongoIntegrationRepository implements IntegrationRepository { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
@Autowired | ||
private IntegrationMongoRepository internalRepository; | ||
|
||
@Autowired | ||
private GraviteeMapper mapper; | ||
|
||
@Override | ||
public Optional<Integration> findById(String s) throws TechnicalException { | ||
logger.debug("Find integration by id [{}]", s); | ||
Integration integration = map(internalRepository.findById(s).orElse(null)); | ||
logger.debug("Find integration by id [{}] - DONE", s); | ||
return Optional.ofNullable(integration); | ||
} | ||
|
||
@Override | ||
public Integration create(Integration integration) throws TechnicalException { | ||
logger.debug("Create integration [{}]", integration.getId()); | ||
Integration createdIntegration = map(internalRepository.insert(map(integration))); | ||
logger.debug("Create integration [{}] - Done", createdIntegration.getId()); | ||
return createdIntegration; | ||
} | ||
|
||
@Override | ||
public Integration update(Integration integration) throws TechnicalException { | ||
if (integration == null) { | ||
throw new IllegalStateException("Integration must not be null"); | ||
} | ||
|
||
final IntegrationMongo integrationMongo = internalRepository.findById(integration.getId()).orElse(null); | ||
if (integrationMongo == null) { | ||
throw new IllegalStateException(String.format("No integration found with id [%s]", integration.getId())); | ||
} | ||
|
||
logger.debug("Update integration [{}]", integration.getId()); | ||
Integration updatedIntegration = map(internalRepository.save(map(integration))); | ||
logger.debug("Update integration [{}] - Done", updatedIntegration.getId()); | ||
return updatedIntegration; | ||
} | ||
|
||
@Override | ||
public void delete(String id) throws TechnicalException { | ||
logger.debug("Delete integration [{}]", id); | ||
internalRepository.deleteById(id); | ||
logger.debug("Delete integration [{}] - Done", id); | ||
} | ||
|
||
@Override | ||
public Set<Integration> findAll() throws TechnicalException { | ||
return internalRepository.findAll().stream().map(this::map).collect(Collectors.toSet()); | ||
} | ||
|
||
@Override | ||
public Page<Integration> findAllByEnvironment(String environmentId, Pageable pageable) throws TechnicalException { | ||
logger.debug("Search by environment ID [{}]", environmentId); | ||
|
||
Page<IntegrationMongo> integrations = internalRepository.findAllByEnvironmentId(environmentId, pageable); | ||
List<Integration> content = mapper.mapIntegrationsList(integrations.getContent()); | ||
|
||
logger.debug("Done searching integrations"); | ||
return new Page<>(content, integrations.getPageNumber(), (int) integrations.getPageElements(), integrations.getTotalElements()); | ||
} | ||
|
||
private Integration map(IntegrationMongo integrationMongo) { | ||
return mapper.map(integrationMongo); | ||
} | ||
|
||
private IntegrationMongo map(Integration integration) { | ||
return mapper.map(integration); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...avitee/repository/mongodb/management/internal/integration/IntegrationMongoRepository.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,27 @@ | ||
/* | ||
* Copyright © 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.repository.mongodb.management.internal.integration; | ||
|
||
import io.gravitee.repository.mongodb.management.internal.model.IntegrationMongo; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* @author Remi Baptiste (remi.baptiste at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
@Repository | ||
public interface IntegrationMongoRepository extends MongoRepository<IntegrationMongo, String>, IntegrationMongoRepositoryCustom {} |
24 changes: 24 additions & 0 deletions
24
.../repository/mongodb/management/internal/integration/IntegrationMongoRepositoryCustom.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,24 @@ | ||
/* | ||
* Copyright © 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.repository.mongodb.management.internal.integration; | ||
|
||
import io.gravitee.common.data.domain.Page; | ||
import io.gravitee.repository.management.api.search.Pageable; | ||
import io.gravitee.repository.mongodb.management.internal.model.IntegrationMongo; | ||
|
||
public interface IntegrationMongoRepositoryCustom { | ||
Page<IntegrationMongo> findAllByEnvironmentId(String environmentId, Pageable pageable); | ||
} |
52 changes: 52 additions & 0 deletions
52
...ee/repository/mongodb/management/internal/integration/IntegrationMongoRepositoryImpl.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,52 @@ | ||
/* | ||
* Copyright © 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.repository.mongodb.management.internal.integration; | ||
|
||
import io.gravitee.common.data.domain.Page; | ||
import io.gravitee.repository.management.api.search.Pageable; | ||
import io.gravitee.repository.mongodb.management.internal.model.IntegrationMongo; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@AllArgsConstructor | ||
public class IntegrationMongoRepositoryImpl implements IntegrationMongoRepositoryCustom { | ||
|
||
private final MongoTemplate mongoTemplate; | ||
|
||
@Override | ||
public Page<IntegrationMongo> findAllByEnvironmentId(String environmentId, Pageable pageable) { | ||
Query query = new Query(); | ||
query.addCriteria(Criteria.where("environmentId").is(environmentId)); | ||
query.with(Sort.by(Sort.Direction.DESC, "updatedAt")); | ||
|
||
long total = mongoTemplate.count(query, IntegrationMongo.class); | ||
|
||
if (pageable != null) { | ||
query.with(PageRequest.of(pageable.pageNumber(), pageable.pageSize())); | ||
} | ||
|
||
List<IntegrationMongo> integrations = mongoTemplate.find(query, IntegrationMongo.class); | ||
|
||
return new Page<>(integrations, (pageable != null) ? pageable.pageNumber() : 0, integrations.size(), total); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../main/java/io/gravitee/repository/mongodb/management/internal/model/IntegrationMongo.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,44 @@ | ||
/* | ||
* Copyright © 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.repository.mongodb.management.internal.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
/** | ||
* @author Remi Baptiste (remi.baptiste at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
@Getter | ||
@Setter | ||
@Document(collection = "#{@environment.getProperty('management.mongodb.prefix')}integration") | ||
public class IntegrationMongo extends Auditable { | ||
|
||
@Id | ||
private String id; | ||
|
||
private String name; | ||
|
||
private String description; | ||
|
||
private String provider; | ||
|
||
private String environmentId; | ||
|
||
public IntegrationMongo() {} | ||
} |
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
Oops, something went wrong.