Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
b84c311921 | |||
63d34e6044 | |||
188059e0f3 |
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.inteligr8.alfresco.activiti</groupId>
|
||||
<artifactId>model-share-activiti-app-ext</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Model Share APS Extension</name>
|
||||
|
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.alfresco.activiti.share;
|
||||
|
||||
import org.activiti.engine.delegate.event.ActivitiEntityEvent;
|
||||
import org.activiti.engine.delegate.event.ActivitiEvent;
|
||||
import org.activiti.engine.delegate.event.ActivitiEventListener;
|
||||
import org.activiti.engine.delegate.event.ActivitiEventType;
|
||||
import org.activiti.engine.impl.persistence.entity.Entity;
|
||||
|
||||
public interface ActivitiEntityEventListener extends ActivitiEventListener {
|
||||
|
||||
@Override
|
||||
default void onEvent(ActivitiEvent event) {
|
||||
ActivitiEntityEvent eevent = (ActivitiEntityEvent) event;
|
||||
this.onEntityEvent(event.getType(), (Entity) eevent.getEntity());
|
||||
}
|
||||
|
||||
void onEntityEvent(ActivitiEventType eventType, Entity entity);
|
||||
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.alfresco.activiti.share;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.activiti.engine.ProcessEngine;
|
||||
import org.activiti.engine.delegate.event.ActivitiEvent;
|
||||
import org.activiti.engine.repository.Model;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class EngineStartEventListener extends NoFailActivitiEventListener {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Value("${inteligr8.modelShareExtension.modelChunkSize:50}")
|
||||
private int modelChunkSize;
|
||||
|
||||
@Autowired
|
||||
private ProcessEngine services;
|
||||
|
||||
@Autowired
|
||||
private ModelShareWorker shareWorker;
|
||||
|
||||
@Override
|
||||
public void onEvent(ActivitiEvent event) {
|
||||
this.logger.info("Starting to query all models to share all of them");
|
||||
|
||||
int page = 1;
|
||||
int perPage = this.modelChunkSize;
|
||||
|
||||
List<Model> models = this.services.getRepositoryService().createModelQuery().listPage((page-1)*perPage, perPage);
|
||||
while (!models.isEmpty()) {
|
||||
for (Model model : models) {
|
||||
this.logger.debug("Discovered model: {}: {}: {}", model.getCategory(), model.getId(), model.getName());
|
||||
this.shareWorker.share(model);
|
||||
}
|
||||
|
||||
page++;
|
||||
models = this.services.getRepositoryService().createModelQuery().listPage((page-1)*perPage, perPage);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.alfresco.activiti.share;
|
||||
|
||||
import org.activiti.engine.delegate.event.ActivitiEventType;
|
||||
import org.activiti.engine.impl.persistence.entity.Entity;
|
||||
import org.activiti.engine.impl.persistence.entity.ModelEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ModelEntityEventListener extends NoFailActivitiEventListener implements ActivitiEntityEventListener {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private ModelShareWorker shareWorker;
|
||||
|
||||
@Override
|
||||
public void onEntityEvent(ActivitiEventType eventType, Entity entity) {
|
||||
this.validate(eventType);
|
||||
|
||||
if (entity instanceof ModelEntity) {
|
||||
ModelEntity mentity = (ModelEntity) entity;
|
||||
this.logger.debug("Caught model event: {}: {}: {}: {}", mentity.getCategory(), entity.getId(), mentity.getKey(), mentity.getName());
|
||||
this.shareWorker.share(mentity);
|
||||
} else {
|
||||
this.logger.trace("Ignoring entity type: {}", entity.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
private void validate(ActivitiEventType eventType) {
|
||||
switch (eventType) {
|
||||
case ENTITY_CREATED:
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -14,12 +14,11 @@
|
||||
*/
|
||||
package com.inteligr8.alfresco.activiti.share;
|
||||
|
||||
import org.activiti.engine.ProcessEngine;
|
||||
import org.activiti.engine.delegate.event.ActivitiEventType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@@ -28,43 +27,31 @@ public class ModelShareExtension implements Bootstrappable {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private ProcessEngine services;
|
||||
|
||||
@Autowired
|
||||
private ModelEntityEventListener entityListener;
|
||||
|
||||
@Autowired
|
||||
private EngineStartEventListener startupListener;
|
||||
|
||||
/**
|
||||
* On startup, scan all models and share them according to the configuration defined elsewhere.
|
||||
*/
|
||||
@Value("${inteligr8.modelShareExtension.shareAllModelsOnStartup:false}")
|
||||
private boolean shareAllModelsOnStartup;
|
||||
private ModelShareWorker worker;
|
||||
|
||||
@Value("${inteligr8.modelShareExtension.enabled:true}")
|
||||
private boolean enabled;
|
||||
|
||||
private boolean bootstrapped;
|
||||
|
||||
@Override
|
||||
public void onBootstrap() {
|
||||
this.logger.trace("onBootstrap()");
|
||||
|
||||
this.registerListeners();
|
||||
|
||||
this.logger.info("Model Share Extension initialized");
|
||||
if (this.enabled) {
|
||||
this.bootstrapped = true;
|
||||
this.logger.info("Model Share Extension initialized");
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
this.logger.info("registerListeners()");
|
||||
// execute every 10 minutes
|
||||
@Scheduled(fixedRate = 600000)
|
||||
private void scheduled() {
|
||||
if (!this.enabled || !this.bootstrapped)
|
||||
return;
|
||||
|
||||
this.services.getRuntimeService().addEventListener(
|
||||
this.entityListener,
|
||||
ActivitiEventType.ENTITY_CREATED);
|
||||
|
||||
if (this.shareAllModelsOnStartup) {
|
||||
// we can't use ENGINE_CREATED as it has already been created
|
||||
this.services.getRuntimeService().addEventListener(
|
||||
this.startupListener,
|
||||
ActivitiEventType.ENGINE_CREATED);
|
||||
this.startupListener.onEvent(null);
|
||||
}
|
||||
this.logger.trace("scheduled()");
|
||||
this.worker.share();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.activiti.engine.ProcessEngine;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -47,6 +48,9 @@ public class ModelShareWorker implements Bootstrappable {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Value("${inteligr8.modelShareExtension.modelChunkSize:50}")
|
||||
private int modelChunkSize;
|
||||
|
||||
@Value("${inteligr8.modelShareExtension.shareChunkSize:25}")
|
||||
private int shareChunkSize;
|
||||
|
||||
@@ -74,6 +78,9 @@ public class ModelShareWorker implements Bootstrappable {
|
||||
@Value("${inteligr8.modelShareExtension.groups.canWriteForms:#{null}}")
|
||||
private String writeFormDefsGroupNames;
|
||||
|
||||
@Autowired
|
||||
private ProcessEngine services;
|
||||
|
||||
@Autowired
|
||||
private ModelShareService shareService;
|
||||
|
||||
@@ -199,6 +206,30 @@ public class ModelShareWorker implements Bootstrappable {
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
public void share() {
|
||||
this.logger.trace("Discovering models ...");
|
||||
|
||||
long modelCount = 0L;
|
||||
int page = 1;
|
||||
int perPage = this.modelChunkSize;
|
||||
|
||||
List<org.activiti.engine.repository.Model> models = this.services.getRepositoryService().createModelQuery().listPage((page-1)*perPage, perPage);
|
||||
while (!models.isEmpty()) {
|
||||
this.logger.trace("Fetched page #{} of {} models", page, models.size());
|
||||
|
||||
for (org.activiti.engine.repository.Model model : models) {
|
||||
this.logger.debug("Discovered model: {}: {}: {}", model.getCategory(), model.getId(), model.getName());
|
||||
this.share(model);
|
||||
}
|
||||
|
||||
modelCount += models.size();
|
||||
page++;
|
||||
models = this.services.getRepositoryService().createModelQuery().listPage((page-1)*perPage, perPage);
|
||||
}
|
||||
|
||||
this.logger.trace("Discovered {} models", modelCount);
|
||||
}
|
||||
|
||||
public void share(org.activiti.engine.repository.Model orgModel) {
|
||||
Model model = (Model) this.modelService.getModel(Long.valueOf(orgModel.getId()));
|
||||
Map<HashableGroup, SharePermission> shares = this.fetchCurrentModelShares(model);
|
||||
@@ -268,8 +299,8 @@ public class ModelShareWorker implements Bootstrappable {
|
||||
}
|
||||
|
||||
private void share(Model model, HashableGroup group, SharePermission permission) {
|
||||
this.logger.debug("Sharing model with group: {}: {}: {}", model.getId(), model.getName(), group);
|
||||
this.shareService.shareModelWithGroup(model, group.getGroup(), permission);
|
||||
this.logger.info("Sharing model with group: {}: {}: {}", model.getId(), model.getName(), group);
|
||||
this.shareService.shareModelWithGroup(model, group.getGroup(), permission).getShareDate();
|
||||
}
|
||||
|
||||
public void unshareAll(Model model) {
|
||||
|
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.alfresco.activiti.share;
|
||||
|
||||
import org.activiti.engine.delegate.event.ActivitiEventListener;
|
||||
|
||||
public abstract class NoFailActivitiEventListener implements ActivitiEventListener {
|
||||
|
||||
@Override
|
||||
public boolean isFailOnException() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user