Created
April 21, 2014 08:52
-
-
Save DemkaAge/11136707 to your computer and use it in GitHub Desktop.
Ejb, FileNet in transaction mode.
This file contains hidden or 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
package ru.brbpm.lecm.server.samples; | |
import com.filenet.api.core.Document; | |
import com.filenet.api.core.Folder; | |
import ru.brbpm.lecm.utils.server.ejb.ServiceInterceptor; | |
import javax.annotation.Resource; | |
import javax.annotation.security.DeclareRoles; | |
import javax.annotation.security.RolesAllowed; | |
import javax.ejb.EJB; | |
import javax.ejb.SessionContext; | |
import javax.ejb.Stateless; | |
import javax.interceptor.Interceptors; | |
/** | |
* Created by dshahovkin on 04.04.2014. =D | |
*/ | |
@Stateless | |
@DeclareRoles("Everyone") | |
@RolesAllowed("Everyone") | |
@Interceptors({ServiceInterceptor.class}) | |
public class ComplexServiceImpl implements ComplexServiceLocal, ComplexServiceRemote { | |
@Resource | |
private SessionContext context; | |
@EJB | |
private InnerServiceLocal innerServiceLocal; | |
@EJB | |
private FnServiceLocal fnServiceLocal; | |
public ComplexServiceImpl() { | |
} | |
@Override | |
public String helloService() { | |
return "ComplexServiceImpl"; | |
} | |
@Override | |
public String getUserPrincipal() { | |
return context.getCallerPrincipal() == null ? "null" : context.getCallerPrincipal().toString(); | |
} | |
@Override | |
public String helloInnerService() { | |
return innerServiceLocal.helloService(); | |
} | |
@Override | |
public String getInnerServiceUserPrincipal() { | |
return innerServiceLocal.getUserPrincipal(); | |
} | |
@Override | |
public String getInnerServiceCeUserPrincipal() { | |
return innerServiceLocal.getCeUserPrincipal(); | |
} | |
@Override | |
public void runInnerServiceStuffMethod() { | |
Folder folder = innerServiceLocal.createFolder(); | |
Document document = fnServiceLocal.createDocument(folder); | |
context.setRollbackOnly(); | |
} | |
} |
This file contains hidden or 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
package ru.brbpm.lecm.server.samples; | |
import javax.ejb.Local; | |
/** | |
* Created by dshahovkin on 04.04.2014. =D | |
*/ | |
@Local | |
public interface ComplexServiceLocal extends ComplexServiceRemote { | |
} |
This file contains hidden or 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
package ru.brbpm.lecm.server.samples; | |
import javax.ejb.Remote; | |
/** | |
* Created by dshahovkin on 04.04.2014. =D | |
*/ | |
@Remote | |
public interface ComplexServiceRemote { | |
String helloService(); | |
String getUserPrincipal(); | |
String helloInnerService(); | |
String getInnerServiceUserPrincipal(); | |
String getInnerServiceCeUserPrincipal(); | |
void runInnerServiceStuffMethod(); | |
} |
This file contains hidden or 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
package ru.brbpm.lecm.server.samples; | |
import com.filenet.api.constants.*; | |
import com.filenet.api.core.*; | |
import com.filenet.api.util.ConfigurationParameters; | |
import ru.brbpm.lecm.shared.api.ConfigServiceLocal; | |
import ru.brbpm.lecm.shared.constants.ConnectionConstants; | |
import ru.brbpm.lecm.utils.server.ejb.ServiceInterceptor; | |
import javax.annotation.PostConstruct; | |
import javax.annotation.Resource; | |
import javax.annotation.security.DeclareRoles; | |
import javax.annotation.security.RolesAllowed; | |
import javax.annotation.security.RunAs; | |
import javax.ejb.EJB; | |
import javax.ejb.SessionContext; | |
import javax.ejb.Stateless; | |
import javax.interceptor.Interceptors; | |
/** | |
* Created by dshahovkin on 07.04.2014. =D | |
*/ | |
@DeclareRoles({"ConfigServiceReader", "Users"}) | |
@RolesAllowed({"ConfigServiceReader", "Users"}) | |
@RunAs("ConfigServiceReader") | |
@Interceptors({ServiceInterceptor.class}) | |
@Stateless | |
public class FnServiceImpl implements FnServiceLocal, FnServiceRemote { | |
@Resource | |
private SessionContext context; | |
@EJB | |
private ConfigServiceLocal configServiceLocal; | |
private Connection connection; | |
@PostConstruct | |
public void init() { | |
ConfigurationParameters configurationParameter = new ConfigurationParameters(); | |
configurationParameter.setParameter(ConfigurationParameter.CONNECTION_PARTICIPATES_IN_TRANSACTION, true); | |
connection = Factory.Connection.getConnection(configServiceLocal.getProperty(ConnectionConstants | |
.CE_URI), configurationParameter); | |
} | |
@Override | |
public Document createDocument(Folder folder) { | |
Document document = Factory.Document.createInstance(folder.getObjectStore(), "Document"); | |
document.save(RefreshMode.REFRESH); | |
// Check in the document | |
document.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION); | |
document.save(RefreshMode.NO_REFRESH); | |
ReferentialContainmentRelationship rcr = folder.file(document, | |
AutoUniqueName.AUTO_UNIQUE, "New Document via Java API", | |
DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE); | |
rcr.save(RefreshMode.NO_REFRESH); | |
return document; | |
} | |
} |
This file contains hidden or 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
package ru.brbpm.lecm.server.samples; | |
import com.filenet.api.core.Document; | |
import com.filenet.api.core.Folder; | |
import javax.ejb.Local; | |
/** | |
* Created by dshahovkin on 07.04.2014. =D | |
*/ | |
@Local | |
public interface FnServiceLocal { | |
Document createDocument(Folder folder); | |
} |
This file contains hidden or 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
package ru.brbpm.lecm.server.samples; | |
import javax.ejb.Remote; | |
/** | |
* Created by dshahovkin on 07.04.2014. =D | |
*/ | |
@Remote | |
public interface FnServiceRemote { | |
} |
This file contains hidden or 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
package ru.brbpm.lecm.server.samples; | |
import com.filenet.api.constants.*; | |
import com.filenet.api.core.*; | |
import com.filenet.api.security.User; | |
import com.filenet.api.util.ConfigurationParameters; | |
import ru.brbpm.lecm.shared.api.ConfigServiceLocal; | |
import ru.brbpm.lecm.shared.constants.ConnectionConstants; | |
import ru.brbpm.lecm.utils.server.ejb.ServiceInterceptor; | |
import javax.annotation.PostConstruct; | |
import javax.annotation.Resource; | |
import javax.annotation.security.DeclareRoles; | |
import javax.annotation.security.RolesAllowed; | |
import javax.annotation.security.RunAs; | |
import javax.ejb.EJB; | |
import javax.ejb.SessionContext; | |
import javax.ejb.Stateless; | |
import javax.interceptor.Interceptors; | |
/** | |
* Created by dshahovkin on 04.04.2014. =D | |
*/ | |
@DeclareRoles({"ConfigServiceReader", "Users"}) | |
@RolesAllowed({"ConfigServiceReader", "Users"}) | |
@RunAs("ConfigServiceReader") | |
@Interceptors({ServiceInterceptor.class}) | |
@Stateless | |
public class InnerServiceImpl implements InnerServiceLocal, InnerServiceRemote { | |
@Resource | |
private SessionContext context; | |
@EJB | |
private ConfigServiceLocal configServiceLocal; | |
private Connection connection; | |
@Override | |
public String helloService() { | |
return "InnerServiceImpl"; | |
} | |
@Override | |
public String getUserPrincipal() { | |
return context.getCallerPrincipal() == null ? "null" : context.getCallerPrincipal().toString(); | |
} | |
@PostConstruct | |
public void init() { | |
ConfigurationParameters configurationParameter = new ConfigurationParameters(); | |
configurationParameter.setParameter(ConfigurationParameter.CONNECTION_PARTICIPATES_IN_TRANSACTION, true); | |
connection = Factory.Connection.getConnection(configServiceLocal.getProperty(ConnectionConstants | |
.CE_URI), configurationParameter); | |
} | |
@Override | |
public String getCeUserPrincipal() { | |
User user = Factory.User.fetchCurrent(connection, null); | |
return user.get_DisplayName(); | |
} | |
@Override | |
public Folder createFolder() { | |
Domain domain = Factory.Domain.getInstance(connection, null); | |
ObjectStore objectStore = Factory.ObjectStore.getInstance(domain, configServiceLocal.getProperty(ConnectionConstants.CE_SYSTEM_OS)); | |
Folder testFolder = Factory.Folder.fetchInstance(objectStore, "/Test", null); | |
Folder testSubFolder = testFolder.createSubFolder("testSubFolder"); | |
testSubFolder.save(RefreshMode.NO_REFRESH); | |
return testSubFolder; | |
} | |
} |
This file contains hidden or 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
package ru.brbpm.lecm.server.samples; | |
import com.filenet.api.core.Folder; | |
import javax.ejb.Local; | |
/** | |
* Created by dshahovkin on 04.04.2014. =D | |
*/ | |
@Local | |
public interface InnerServiceLocal extends InnerServiceRemote { | |
Folder createFolder(); | |
} |
This file contains hidden or 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
package ru.brbpm.lecm.server.samples; | |
import javax.ejb.Remote; | |
/** | |
* Created by dshahovkin on 04.04.2014. =D | |
*/ | |
@Remote | |
public interface InnerServiceRemote { | |
String helloService(); | |
String getUserPrincipal(); | |
String getCeUserPrincipal(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment