bIT_sosswald
Returning Responder

How to get a ProjectEnvironment inside of an executable to init GenericConfiguration object

Jump to solution

Hi all,

I want to bring up this question again: https://community.crownpeak.com/t5/Questions-Answers/Is-there-a-way-to-get-a-ProjectEnvironment-from...

How do I get an instance of ProjectEnvironment?
Is there a way to obtain this object from an Agent, a Connection, or something else?

Background:

We use the e-Spirit Generic Configuration (which is an great tool to create configuration panels for the ServerManager!). This works perfectly fine.
But we now need to change a project configuration by a server schedule job. (To reset credentials in the project configuration that will expire soon.)

For this I would like to the the GenericConfiguration also. But since the recreation of the credentials will be done in a server schedule job I do not have a ProjectEnvironment to call the init() method of the generic configuration panel.

My wish would to do something like this:

private void foo() {
AProjectAppConfiguration projectAppConfiguration = new AProjectAppConfiguration();
projectAppConfiguration.init(null, null, projectEnvironment);
projectAppConfiguration.load();
projectAppConfiguration.setApplicationSecret("TopSecret");
projectAppConfiguration.store();
}

But for this I need a ProjectEnvironment. 🤷🏻‍♂️

 

Thanks for your help.

Sandro

0 Kudos
1 Solution

Accepted Solutions
bIT_sosswald
Returning Responder

I solved the issue with an ugly solution, but it works.

I created my own implementation of ProjectEnvironment which just returns the needed values to initialize the GenericConfiguration with the method getConfDir().

When passing the module name, project app name and project I can get the FileHandle to the project app configuration directory which is used by the init() call on the GenericConfiguration panel. - This solves my problem and I can use the GenericConfiguration panel to change project app configurations inside of an executable using a comfortable API.

public class ProjectAppConfigEnvironment implements ProjectEnvironment {


private final Project project;
private final FileSystem<? extends FileHandle> fileSystem;

/**
* Creates a new instance.
*
* @param moduleName The name of the FirstSpirit module containing the project app in focus.
* @param projectAppName The name of the project app in focus.
* @param project The project in which the project app is installed to.
*/
public ProjectAppConfigEnvironment(String moduleName, String projectAppName, Project project) {
this.project = project;
ModuleAdminAgent moduleAdminAgent = project.getUserService().getConnection().getBroker().requireSpecialist(ModuleAdminAgent.TYPE);
fileSystem = moduleAdminAgent.getProjectAppConfig(moduleName, projectAppName, project);
}

/**
* Gets the configuration directory of the project app.
*
* @return Access to the project-app configuration directory.
* @see <a href="https://docs.e-spirit.com/odfs/dev/de/espirit/firstspirit/agency/ModuleAdminAgent.html#getProjectAppConfig(java.lang.String,java.lang.String,de.espirit.firstspirit.access.project.Project)">ModuleAdminAgent.getProjectAppConfig</a>
*/
@Override
public @NotNull FileSystem<? extends FileHandle> getConfDir() {
return fileSystem;
}

@SneakyThrows
@Override
public @Nullable FileSystem<? extends FileHandle> getDataDir() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public @Nullable FileSystem<? extends FileHandle> getLogDir() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public Connection getConnection() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public SpecialistsBroker getBroker() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public ComponentDescriptor.Scope getScope() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public @Nullable String getInstalledVersion() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public long getProjectId() {
return project.getId();
}

@SneakyThrows
@Override
public @Nullable Project getProject() {
return project;
}
}

View solution in original post

0 Kudos
1 Reply
bIT_sosswald
Returning Responder

I solved the issue with an ugly solution, but it works.

I created my own implementation of ProjectEnvironment which just returns the needed values to initialize the GenericConfiguration with the method getConfDir().

When passing the module name, project app name and project I can get the FileHandle to the project app configuration directory which is used by the init() call on the GenericConfiguration panel. - This solves my problem and I can use the GenericConfiguration panel to change project app configurations inside of an executable using a comfortable API.

public class ProjectAppConfigEnvironment implements ProjectEnvironment {


private final Project project;
private final FileSystem<? extends FileHandle> fileSystem;

/**
* Creates a new instance.
*
* @param moduleName The name of the FirstSpirit module containing the project app in focus.
* @param projectAppName The name of the project app in focus.
* @param project The project in which the project app is installed to.
*/
public ProjectAppConfigEnvironment(String moduleName, String projectAppName, Project project) {
this.project = project;
ModuleAdminAgent moduleAdminAgent = project.getUserService().getConnection().getBroker().requireSpecialist(ModuleAdminAgent.TYPE);
fileSystem = moduleAdminAgent.getProjectAppConfig(moduleName, projectAppName, project);
}

/**
* Gets the configuration directory of the project app.
*
* @return Access to the project-app configuration directory.
* @see <a href="https://docs.e-spirit.com/odfs/dev/de/espirit/firstspirit/agency/ModuleAdminAgent.html#getProjectAppConfig(java.lang.String,java.lang.String,de.espirit.firstspirit.access.project.Project)">ModuleAdminAgent.getProjectAppConfig</a>
*/
@Override
public @NotNull FileSystem<? extends FileHandle> getConfDir() {
return fileSystem;
}

@SneakyThrows
@Override
public @Nullable FileSystem<? extends FileHandle> getDataDir() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public @Nullable FileSystem<? extends FileHandle> getLogDir() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public Connection getConnection() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public SpecialistsBroker getBroker() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public ComponentDescriptor.Scope getScope() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public @Nullable String getInstalledVersion() {
throw new OperationNotSupportedException();
}

@SneakyThrows
@Override
public long getProjectId() {
return project.getId();
}

@SneakyThrows
@Override
public @Nullable Project getProject() {
return project;
}
}
0 Kudos