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

661 create a new module script service for release 14h meveo #711

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -649,24 +649,24 @@ public PersistenceActionResult createOrUpdate(Repository repository, CustomEntit
throw new RuntimeException(e);
}

for (var storage : cet.getAvailableStorages()) {
StorageImpl impl = provider.findImplementation(storage);
PersistenceActionResult results = null;
for (var storageConf : repository.getStorageConfigurations(storage)) {
var intermediateResults = impl.createOrUpdate(repository, storageConf, ceiAfterPreEvents, customFieldTemplates, foundId);
if (intermediateResults != null) {
results = intermediateResults;
try {

for (var storage : cet.getAvailableStorages()) {
StorageImpl impl = provider.findImplementation(storage);
PersistenceActionResult results = null;
for (var storageConf : repository.getStorageConfigurations(storage)) {
var intermediateResults = impl.createOrUpdate(repository, storageConf, ceiAfterPreEvents, customFieldTemplates, foundId);
if (intermediateResults != null) {
results = intermediateResults;
}
}
}
if (results != null) {
uuid = results.getBaseEntityUuid();
if (foundId == null) {
ceiAfterPreEvents.setUuid(uuid);
if (results != null) {
uuid = results.getBaseEntityUuid();
if (foundId == null) {
ceiAfterPreEvents.setUuid(uuid);
}
}
}
}

try {

if(cetClassInstance != null) {
if(foundId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
import org.meveo.service.job.JobExecutionService;
import org.meveo.service.job.JobInstanceService;
import org.meveo.service.script.ScriptInstanceService;
import org.meveo.service.script.module.ModuleScriptInterface;
import org.meveo.service.script.module.ModuleScriptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -149,6 +151,9 @@ public class MeveoModuleService extends GenericModuleService<MeveoModule> {

@Inject
private UserService userService;

@Inject
private ModuleScriptService moduleScriptService;

@Inject
CommitMessageBean commitMessageBean;
Expand Down Expand Up @@ -546,6 +551,10 @@ public void onCftDeleted(@Observes @Removed CustomFieldTemplate cft) {

public void releaseModule(MeveoModule entity, String nextVersion) throws BusinessException {
entity = findById(entity.getId(), Arrays.asList("moduleItems", "patches", "moduleDependencies", "moduleFiles"));
ModuleScriptInterface moduleScript = null;
if (entity.getScript() != null) {
moduleScript = moduleScriptService.preRelease(entity.getScript().getCode(), entity);
}
ModuleRelease moduleRelease = new ModuleRelease();
moduleRelease.setCode(entity.getCode());
moduleRelease.setDescription(entity.getDescription());
Expand Down Expand Up @@ -628,11 +637,13 @@ public void releaseModule(MeveoModule entity, String nextVersion) throws Busines
} catch (IOException e) {
throw new BusinessException("Can't install artifact to .m2", e);
}

entity.setCurrentVersion(nextVersion);
moduleRelease.setMeveoModule(entity);
entity.getReleases().add(moduleRelease);
this.update(entity);
if (moduleScript != null) {
moduleScriptService.postRelease(moduleScript, entity);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TypedQuery;

import org.apache.commons.lang3.StringUtils;
import org.meveo.admin.exception.BusinessException;
Expand Down Expand Up @@ -2485,19 +2486,24 @@ public void setCfValues(ICustomFieldEntity entity, Map<String, CustomFieldTempla
entityReferenceWrapper.setId(((BigInteger) value).longValue());
value = entityReferenceWrapper;

} /* else if (cetField.getValue().getFieldType().name().equals("ENTITY") && value instanceof String) {
EntityReferenceWrapper entityReferenceWrapper = new EntityReferenceWrapper();
if (cetField.getValue().getEntityClazz().equals(User.class.getName())) {
User user = userService.findById(((BigInteger) value).longValue());
entityReferenceWrapper.setCode(user.getUserName());
} else if (cetField.getValue().getEntityClazz().equals(Provider.class.getName())) {
Provider provider = providerService.findById(((BigInteger) value).longValue());
entityReferenceWrapper.setCode(provider.getCode());
}
entityReferenceWrapper.setClassname(cetField.getValue().getEntityClazz());
entityReferenceWrapper.setId(((BigInteger) value).longValue());
value = entityReferenceWrapper;
} */
} else if (cetField.getValue().getFieldType().name().equals("ENTITY") && value instanceof String) {
if (cetField.getValue().getEntityClazzCetCode().contains(".")) { // We are dealing with BusinessEntity
TypedQuery<Long> query = emWrapper.getEntityManager().createQuery(
"SELECT id FROM " + cetField.getValue().getEntityClazz() + " WHERE code = :code"
, Long.class);
query.setParameter("code", value);

try {
EntityReferenceWrapper entityReferenceWrapper = new EntityReferenceWrapper();
entityReferenceWrapper.setClassname(cetField.getValue().getEntityClazz());
entityReferenceWrapper.setId(query.getSingleResult());
entityReferenceWrapper.setCode((String) value);
value = entityReferenceWrapper;
} catch (Exception e) {
//NOOP
}
}
}

setCFValue(entity, cetField.getKey(), value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@
* @author Andrius Karpavicius
**/
public class ModuleScript extends Script implements ModuleScriptInterface {

@Override
public void preReleaseModule(Map<String, Object> methodContext) throws BusinessException {
}

@Override
public void postReleaseModule(Map<String, Object> methodContext) throws BusinessException {
}

@Override
public void preInstallModule(Map<String, Object> methodContext) throws BusinessException {
}

@Override
public void postInstallModule(java.util.Map<String, Object> methodContext) throws BusinessException {
public void postInstallModule(Map<String, Object> methodContext) throws BusinessException {
}

@Override
Expand All @@ -27,19 +35,19 @@ public void postUninstallModule(Map<String, Object> methodContext) throws Busine
}

@Override
public void preEnableModule(java.util.Map<String, Object> methodContext) throws BusinessException {
public void preEnableModule(Map<String, Object> methodContext) throws BusinessException {
}

@Override
public void postEnableModule(java.util.Map<String, Object> methodContext) throws BusinessException {
public void postEnableModule(Map<String, Object> methodContext) throws BusinessException {
}

@Override
public void preDisableModule(java.util.Map<String, Object> methodContext) throws BusinessException {
public void preDisableModule(Map<String, Object> methodContext) throws BusinessException {
}

@Override
public void postDisableModule(java.util.Map<String, Object> methodContext) throws BusinessException {
public void postDisableModule(Map<String, Object> methodContext) throws BusinessException {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
import org.meveo.service.script.ScriptInterface;

public interface ModuleScriptInterface extends ScriptInterface {

/**
* Module being released - called before the release starts
*
* @param methodContext Method variables in a form of a map where CONTEXT_ENTITY=MeveoModule
*
* @throws BusinessException business exception.
*/
public void preReleaseModule(Map<String, Object> methodContext) throws BusinessException;

/**
* Module being released - called after the release complete successfully
*
* @param methodContext Method variables in a form of a map where CONTEXT_ENTITY=MeveoModule
*
* @throws BusinessException business exception.
*/
public void postReleaseModule(Map<String, Object> methodContext) throws BusinessException;

/**
* Module being installed - called before installation starts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ public class ModuleScriptService implements Serializable {

@Inject
private ScriptInstanceService scriptInstanceService;

public ModuleScriptInterface preRelease(String scriptCode, MeveoModule module) throws BusinessException {
ModuleScriptInterface scriptInterface = (ModuleScriptInterface) scriptInstanceService.getScriptInstance(scriptCode);
Map<String, Object> scriptContext = new HashMap<String, Object>();
scriptInterface.preReleaseModule(scriptContext);
return scriptInterface;
}

public void postRelease(ModuleScriptInterface scriptInterface, MeveoModule module) throws BusinessException {
Map<String, Object> scriptContext = new HashMap<String, Object>();
scriptContext.put(Script.CONTEXT_ENTITY, module);
scriptInterface.postReleaseModule(scriptContext);
}

public ModuleScriptInterface preInstallModule(String scriptCode, MeveoModule module) throws ElementNotFoundException, InvalidScriptException, BusinessException {
ModuleScriptInterface scriptInterface = (ModuleScriptInterface) scriptInstanceService.getScriptInstance(scriptCode);
Expand Down
2 changes: 2 additions & 0 deletions meveo-model/src/main/java/org/meveo/model/BusinessEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hibernate.annotations.NaturalId;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;

/**
* @author Edward P. Legaspi <czetsuya@gmail.com>
Expand All @@ -40,6 +41,7 @@ public class BusinessEntity extends EnableEntity implements ISearchable {
@Column(name = "code", nullable = false, length = 255)
@Size(max = 255, min = 1)
@NaturalId
@JsonValue
protected String code;

/**
Expand Down