-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from ivannov/FORGE-2120
Forge 2120
- Loading branch information
Showing
6 changed files
with
226 additions
and
17 deletions.
There are no files selected for viewing
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
67 changes: 67 additions & 0 deletions
67
...addon/src/main/java/org/jboss/forge/addons/envers/commands/JpaEntityCreationListener.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,67 @@ | ||
package org.jboss.forge.addons.envers.commands; | ||
|
||
import org.jboss.forge.addon.configuration.Configuration; | ||
import org.jboss.forge.addon.configuration.facets.ConfigurationFacet; | ||
import org.jboss.forge.addon.parser.java.resources.JavaResource; | ||
import org.jboss.forge.addon.projects.ProjectFactory; | ||
import org.jboss.forge.addon.projects.Projects; | ||
import org.jboss.forge.addon.ui.command.CommandExecutionListener; | ||
import org.jboss.forge.addon.ui.command.UICommand; | ||
import org.jboss.forge.addon.ui.context.UIExecutionContext; | ||
import org.jboss.forge.addon.ui.context.UISelection; | ||
import org.jboss.forge.addon.ui.result.Result; | ||
import org.jboss.forge.roaster.model.source.JavaClassSource; | ||
|
||
import javax.inject.Inject; | ||
import java.io.FileNotFoundException; | ||
|
||
import static org.jboss.forge.addons.envers.commands.Constants.AUDITED_ANNOTATION; | ||
import static org.jboss.forge.addons.envers.commands.Constants.AUTO_AUDIT_CONFIG_ENTRY; | ||
|
||
/** | ||
* @author Ivan St. Ivanov | ||
*/ | ||
public class JpaEntityCreationListener implements CommandExecutionListener | ||
{ | ||
@Override public void preCommandExecuted(UICommand uiCommand, UIExecutionContext uiExecutionContext) | ||
{ | ||
|
||
} | ||
|
||
@Inject | ||
private ProjectFactory projectFactory; | ||
|
||
@Override public void postCommandExecuted(UICommand uiCommand, UIExecutionContext uiExecutionContext, Result result) | ||
{ | ||
String commandName = uiCommand | ||
.getMetadata(uiExecutionContext.getUIContext()) | ||
.getName(); | ||
if (commandName.equals("JPA: New Entity") && projectFactory != null) | ||
{ | ||
Configuration configuration = Projects | ||
.getSelectedProject(projectFactory, uiExecutionContext.getUIContext()) | ||
.getFacet(ConfigurationFacet.class) | ||
.getConfiguration(); | ||
if (configuration.getBoolean(AUTO_AUDIT_CONFIG_ENTRY, false)) | ||
{ | ||
try { | ||
JavaResource resource = (JavaResource) uiExecutionContext | ||
.getUIContext().getSelection().get(); | ||
JavaClassSource javaClass = resource.getJavaType(); | ||
if (!javaClass.hasAnnotation(AUDITED_ANNOTATION)) { | ||
javaClass.addAnnotation(AUDITED_ANNOTATION); | ||
} | ||
resource.setContents(javaClass); | ||
} catch (FileNotFoundException fnfe) { | ||
fnfe.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override public void postCommandFailure(UICommand uiCommand, UIExecutionContext uiExecutionContext, | ||
Throwable throwable) | ||
{ | ||
|
||
} | ||
} |