Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAE-28451 Add Subproceses to Process Instance #1617

Draft
wants to merge 32 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
425e873
Add subproceeses to process instance
shsahahyland Nov 22, 2024
6220674
Correct Process instance controller
shsahahyland Nov 22, 2024
fa78a9f
try auto commit
shsahahyland Nov 22, 2024
c3be2b4
Apply automatic changes
shsahahyland Nov 22, 2024
af40e89
skip tests
shsahahyland Nov 22, 2024
c7a7d92
Comment acceptance tests
shsahahyland Nov 22, 2024
ef815be
update additional methods
shsahahyland Nov 25, 2024
55d2ed4
Apply automatic changes
shsahahyland Nov 25, 2024
aff97e5
Change subprocess definition
shsahahyland Nov 25, 2024
848ffa8
correct prechecks
shsahahyland Nov 25, 2024
f5aa09c
resolve comments
shsahahyland Nov 25, 2024
3f4c540
update controller
shsahahyland Nov 25, 2024
ad58f4c
Apply automatic changes
shsahahyland Nov 25, 2024
ab26e82
Add ut and it
shsahahyland Nov 26, 2024
93f7a3a
Apply automatic changes
shsahahyland Nov 26, 2024
65c23b1
Add license header
shsahahyland Nov 26, 2024
df1ef8a
Add changed json
shsahahyland Nov 26, 2024
59bb8ed
AAE-28451 Refactor
graric Nov 27, 2024
7b9ace3
AAE-28451 Refactor
graric Nov 27, 2024
c4c9e13
AAE-28451 Refactor
graric Nov 27, 2024
bb55776
AAE-28451 Refactor
graric Nov 27, 2024
ba26cde
Add controller tests
shsahahyland Nov 29, 2024
69cf9e4
Apply automatic changes
shsahahyland Nov 29, 2024
1ace913
Customized Repository unit tests
shsahahyland Dec 2, 2024
76e43c0
Apply automatic changes
shsahahyland Dec 2, 2024
5c925fd
additional mockbean
shsahahyland Dec 2, 2024
11d1ecb
remove auto commit
shsahahyland Dec 2, 2024
aa26e12
IT
shsahahyland Dec 2, 2024
2277a02
Apply automatic changes
shsahahyland Dec 2, 2024
9fbb3f0
remove auto commit
shsahahyland Dec 2, 2024
5047dd9
resolve comments:extend mockito
shsahahyland Dec 3, 2024
9c9ad78
resolve comments:fix assertions
shsahahyland Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
uses: Alfresco/alfresco-build-tools/.github/actions/pre-commit@a0837df06d10de2cae8a99319e8e101a6cbe9083 # v8.4.0
with:
skip_checkout: true
auto-commit: true
shsahahyland marked this conversation as resolved.
Show resolved Hide resolved
- name: Ensure SHA pinned actions
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@5d6ac37a4cef8b8df67f482a8e384987766f0213 # v3.0.17

Expand Down Expand Up @@ -121,7 +122,6 @@ jobs:
- name: Build Activiti Cloud Identity Adapter
run: make docker/activiti-cloud-identity-adapter


acceptance-tests:
runs-on: ubuntu-latest
needs: build
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2017-2020 Alfresco Software, Ltd.
*
* 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 org.activiti.cloud.api.process.model.impl;

import java.util.Objects;
import java.util.Set;
import org.activiti.cloud.api.process.model.QueryCloudProcessInstance;
import org.activiti.cloud.api.process.model.QueryCloudSubprocessInstance;

public class QueryCloudProcessInstanceImpl extends CloudProcessInstanceImpl implements QueryCloudProcessInstance {
shsahahyland marked this conversation as resolved.
Show resolved Hide resolved

private Set<QueryCloudSubprocessInstance> subprocesses;

@Override
public Set<QueryCloudSubprocessInstance> getSubprocesses() {
return subprocesses;
}

@Override
public void setSubprocesses(Set<QueryCloudSubprocessInstance> subprocesses) {
this.subprocesses = subprocesses;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
QueryCloudProcessInstanceImpl other = (QueryCloudProcessInstanceImpl) obj;
return Objects.equals(subprocesses, other.subprocesses);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), subprocesses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.activiti.cloud.api.process.model.IntegrationError;
import org.activiti.cloud.api.process.model.IntegrationRequest;
import org.activiti.cloud.api.process.model.IntegrationResult;
import org.activiti.cloud.api.process.model.QueryCloudProcessInstance;
import org.activiti.cloud.api.process.model.impl.CloudApplicationImpl;
import org.activiti.cloud.api.process.model.impl.CloudBPMNActivityImpl;
import org.activiti.cloud.api.process.model.impl.CloudIntegrationContextImpl;
Expand All @@ -60,6 +61,7 @@
import org.activiti.cloud.api.process.model.impl.IntegrationErrorImpl;
import org.activiti.cloud.api.process.model.impl.IntegrationRequestImpl;
import org.activiti.cloud.api.process.model.impl.IntegrationResultImpl;
import org.activiti.cloud.api.process.model.impl.QueryCloudProcessInstanceImpl;
import org.activiti.cloud.api.process.model.impl.SyncCloudProcessDefinitionsPayload;
import org.activiti.cloud.api.process.model.impl.SyncCloudProcessDefinitionsResult;
import org.activiti.cloud.api.process.model.impl.events.CloudApplicationDeployedEventImpl;
Expand Down Expand Up @@ -320,6 +322,7 @@ public JavaType resolveAbstractType(DeserializationConfig config, BeanDescriptio
resolver.addMapping(CloudServiceTask.class, CloudServiceTaskImpl.class);
resolver.addMapping(Deployment.class, DeploymentImpl.class);
resolver.addMapping(CloudApplication.class, CloudApplicationImpl.class);
resolver.addMapping(QueryCloudProcessInstance.class, QueryCloudProcessInstanceImpl.class);

module.setAbstractTypes(resolver);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2017-2020 Alfresco Software, Ltd.
*
* 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 org.activiti.cloud.api.process.model;

import java.util.Set;

public interface QueryCloudProcessInstance extends CloudProcessInstance {
Set<QueryCloudSubprocessInstance> getSubprocesses();
shsahahyland marked this conversation as resolved.
Show resolved Hide resolved

void setSubprocesses(Set<QueryCloudSubprocessInstance> subprocesses);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2017-2020 Alfresco Software, Ltd.
*
* 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 org.activiti.cloud.api.process.model;

public class QueryCloudSubprocessInstance {

private String id;
private String processDefinitionName;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getProcessDefinitionName() {
return processDefinitionName;
}

public void setProcessDefinitionName(String processDefinitionName) {
this.processDefinitionName = processDefinitionName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.activiti.cloud.api.process.model.CloudProcessInstance;
import org.activiti.cloud.api.process.model.QueryCloudProcessInstance;
import org.activiti.cloud.api.process.model.QueryCloudSubprocessInstance;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Filter;
Expand Down Expand Up @@ -74,7 +75,7 @@
),
}
)
public class ProcessInstanceEntity extends ActivitiEntityMetadata implements CloudProcessInstance {
public class ProcessInstanceEntity extends ActivitiEntityMetadata implements QueryCloudProcessInstance {

@Id
private String id;
Expand Down Expand Up @@ -221,6 +222,9 @@ public class ProcessInstanceEntity extends ActivitiEntityMetadata implements Clo

private String parentId;

@Transient
private Set<QueryCloudSubprocessInstance> subprocesses;

public ProcessInstanceEntity() {}

public ProcessInstanceEntity(
Expand Down Expand Up @@ -510,4 +514,13 @@ public boolean equals(Object obj) {

return id != null && Objects.equals(id, other.id);
}

@Override
public Set<QueryCloudSubprocessInstance> getSubprocesses() {
return subprocesses;
}

public void setSubprocesses(Set<QueryCloudSubprocessInstance> subprocesses) {
this.subprocesses = subprocesses;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2017-2020 Alfresco Software, Ltd.
*
* 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 org.activiti.cloud.services.query.app.repository;

import org.activiti.cloud.services.query.model.ProcessInstanceEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface CustomizedProcessInstanceRepository {
Page<ProcessInstanceEntity> mapSubprocesses(Page<ProcessInstanceEntity> processInstances, Pageable pageable);

ProcessInstanceEntity mapSubprocesses(ProcessInstanceEntity processInstance);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright 2017-2020 Alfresco Software, Ltd.
*
* 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 org.activiti.cloud.services.query.app.repository;

import com.querydsl.jpa.JPQLQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.activiti.cloud.api.process.model.QueryCloudSubprocessInstance;
import org.activiti.cloud.services.query.model.ProcessInstanceEntity;
import org.activiti.cloud.services.query.model.QProcessInstanceEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.support.Querydsl;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import org.springframework.data.support.PageableExecutionUtils;

public class CustomizedProcessInstanceRepositoryImpl
shsahahyland marked this conversation as resolved.
Show resolved Hide resolved
shsahahyland marked this conversation as resolved.
Show resolved Hide resolved
extends QuerydslRepositorySupport
implements CustomizedProcessInstanceRepository {

private final JPAQueryFactory queryFactory;

public CustomizedProcessInstanceRepositoryImpl(EntityManager entityManager) {
super(ProcessInstanceEntity.class);
this.queryFactory = new JPAQueryFactory(entityManager);
}

@Override
public Page<ProcessInstanceEntity> mapSubprocesses(
Page<ProcessInstanceEntity> processInstances,
Pageable pageable
) {
List<String> parentIds = getParentIds(processInstances);

Page<ProcessInstanceEntity> subprocesses = findSubprocessesByParentIds(parentIds, pageable);

Map<String, Set<QueryCloudSubprocessInstance>> subprocessMap = groupSubprocesses(subprocesses);

setSubprocesses(processInstances, subprocessMap);

return processInstances;
}

@Override
public ProcessInstanceEntity mapSubprocesses(ProcessInstanceEntity processInstance) {
List<ProcessInstanceEntity> subprocesses = findSubprocessesByParentId(processInstance.getId());

if (subprocesses == null || subprocesses.isEmpty()) {
processInstance.setSubprocesses(new HashSet<>());
return processInstance;
}

Set<QueryCloudSubprocessInstance> subprocessSet = subprocesses
.stream()
.map(this::getQueryCloudSubprocessInstance)
.collect(Collectors.toSet());

processInstance.setSubprocesses(subprocessSet);

return processInstance;
}

public QueryCloudSubprocessInstance getQueryCloudSubprocessInstance(ProcessInstanceEntity subprocess) {
QueryCloudSubprocessInstance subProcessInstance = new QueryCloudSubprocessInstance();
subProcessInstance.setId(subprocess.getId());
subProcessInstance.setProcessDefinitionName(subprocess.getProcessDefinitionName());
return subProcessInstance;
}

public List<String> getParentIds(Page<ProcessInstanceEntity> processInstances) {
return processInstances.getContent().stream().map(ProcessInstanceEntity::getId).toList();
}

public Map<String, Set<QueryCloudSubprocessInstance>> groupSubprocesses(Page<ProcessInstanceEntity> subprocesses) {
return subprocesses
.getContent()
.stream()
.collect(
Collectors.groupingBy(
ProcessInstanceEntity::getParentId,
Collectors.mapping(this::getQueryCloudSubprocessInstance, Collectors.toSet())
)
);
}

public void setSubprocesses(
Page<ProcessInstanceEntity> processInstances,
Map<String, Set<QueryCloudSubprocessInstance>> subprocessMap
) {
processInstances
.getContent()
.forEach(processInstance -> {
Set<QueryCloudSubprocessInstance> subprocessSet = subprocessMap.getOrDefault(
processInstance.getId(),
Set.of()
);
processInstance.setSubprocesses(subprocessSet);
});
}

public Page<ProcessInstanceEntity> findSubprocessesByParentIds(List<String> parentIds, Pageable pageable) {
QProcessInstanceEntity processInstanceEntity = QProcessInstanceEntity.processInstanceEntity;

Querydsl querydsl = getQuerydsl();

JPQLQuery<ProcessInstanceEntity> subprocessQuery = queryFactory
.selectFrom(processInstanceEntity)
.where(processInstanceEntity.parentId.in(parentIds));

long totalElements = subprocessQuery.fetchCount();

assert querydsl != null;
List<ProcessInstanceEntity> subprocesses = querydsl.applyPagination(pageable, subprocessQuery).fetch();

return PageableExecutionUtils.getPage(subprocesses, pageable, () -> totalElements);
}

public List<ProcessInstanceEntity> findSubprocessesByParentId(String parentId) {
QProcessInstanceEntity processInstanceEntity = QProcessInstanceEntity.processInstanceEntity;

return queryFactory
.selectFrom(processInstanceEntity)
.where(processInstanceEntity.parentId.eq(parentId))
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public interface ProcessInstanceRepository
JpaSpecificationExecutor<ProcessInstanceEntity>,
QuerydslPredicateExecutor<ProcessInstanceEntity>,
QuerydslBinderCustomizer<QProcessInstanceEntity>,
CustomizedProcessInstanceRepository,
CrudRepository<ProcessInstanceEntity, String> {
@Override
default void customize(QuerydslBindings bindings, QProcessInstanceEntity root) {
Expand Down
Loading
Loading