use of org.broadleafcommerce.common.sandbox.domain.SandBox in project BroadleafCommerce by BroadleafCommerce.
the class AbstractCacheMissAware method buildKey.
/**
* Build the key representing this missed cache item. Will include sandbox and/or site information
* if appropriate.
*
* @param params the appropriate params comprising a unique key for this cache item
* @return the completed key
*/
protected String buildKey(String... params) {
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
SandBox sandBox = null;
if (context != null) {
sandBox = context.getSandBox();
}
String key = StringUtils.join(params, '_');
if (sandBox != null) {
key = sandBox.getId() + "_" + key;
}
Site site = context.getNonPersistentSite();
if (site != null) {
key = key + "_" + site.getId();
}
return key;
}
use of org.broadleafcommerce.common.sandbox.domain.SandBox in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafAdminRequestProcessor method prepareSandBox.
protected void prepareSandBox(WebRequest request, BroadleafRequestContext brc) {
AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser();
if (adminUser == null) {
// clear any sandbox
if (BLCRequestUtils.isOKtoUseSession(request)) {
request.removeAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION);
}
} else {
SandBox sandBox = null;
if (StringUtils.isNotBlank(request.getParameter(SANDBOX_REQ_PARAM))) {
Long sandBoxId = Long.parseLong(request.getParameter(SANDBOX_REQ_PARAM));
sandBox = sandBoxService.retrieveUserSandBoxForParent(adminUser.getId(), sandBoxId);
if (sandBox == null) {
SandBox approvalOrUserSandBox = sandBoxService.retrieveSandBoxManagementById(sandBoxId);
if (approvalOrUserSandBox != null) {
if (approvalOrUserSandBox.getSandBoxType().equals(SandBoxType.USER)) {
sandBox = approvalOrUserSandBox;
} else {
sandBox = sandBoxService.createUserSandBox(adminUser.getId(), approvalOrUserSandBox);
}
}
}
if (BLCRequestUtils.isOKtoUseSession(request)) {
String token = request.getParameter(staleStateProtectionService.getStateVersionTokenParameter());
staleStateProtectionService.compareToken(token);
staleStateProtectionService.invalidateState(true);
}
}
if (sandBox == null) {
Long previouslySetSandBoxId = null;
if (BLCRequestUtils.isOKtoUseSession(request)) {
previouslySetSandBoxId = (Long) request.getAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION);
}
if (previouslySetSandBoxId != null) {
sandBox = sandBoxService.retrieveSandBoxManagementById(previouslySetSandBoxId);
}
}
if (sandBox == null) {
List<SandBox> defaultSandBoxes = sandBoxService.retrieveSandBoxesByType(SandBoxType.DEFAULT);
if (defaultSandBoxes.size() > 1) {
throw new IllegalStateException("Only one sandbox should be configured as default");
}
SandBox defaultSandBox;
if (defaultSandBoxes.size() == 1) {
defaultSandBox = defaultSandBoxes.get(0);
} else {
defaultSandBox = sandBoxService.createDefaultSandBox();
}
sandBox = sandBoxService.retrieveUserSandBoxForParent(adminUser.getId(), defaultSandBox.getId());
if (sandBox == null) {
sandBox = sandBoxService.createUserSandBox(adminUser.getId(), defaultSandBox);
}
}
// If the user just changed sandboxes, we want to update the database record.
Long previouslySetSandBoxId = null;
if (BLCRequestUtils.isOKtoUseSession(request)) {
previouslySetSandBoxId = (Long) request.getAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION);
}
if (previouslySetSandBoxId != null && !sandBox.getId().equals(previouslySetSandBoxId)) {
adminUser.setLastUsedSandBoxId(sandBox.getId());
adminUser = adminSecurityService.saveAdminUser(adminUser);
}
if (BLCRequestUtils.isOKtoUseSession(request)) {
request.setAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, sandBox.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
}
// is used in a different session that it was initiated in. see QA#2576
if (sandBox != null && sandBox.getChildSandBoxes() != null) {
sandBox.getChildSandBoxes().size();
}
brc.setSandBox(sandBox);
brc.setDeployBehavior(deployBehaviorUtil.isProductionSandBoxMode() ? DeployBehavior.CLONE_PARENT : DeployBehavior.OVERWRITE_PARENT);
brc.getAdditionalProperties().put("adminUser", adminUser);
}
}
use of org.broadleafcommerce.common.sandbox.domain.SandBox in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxDaoImpl method retrieveSandBoxesForAuthor.
@Override
public List<SandBox> retrieveSandBoxesForAuthor(Long authorId, SandBoxType sandBoxType) {
CriteriaBuilder builder = sandBoxEntityManager.getCriteriaBuilder();
CriteriaQuery<SandBox> criteria = builder.createQuery(SandBox.class);
Root<SandBoxManagementImpl> sandbox = criteria.from(SandBoxManagementImpl.class);
criteria.select(sandbox.get("sandBox").as(SandBox.class));
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(builder.equal(sandbox.get("sandBox").get("author"), authorId));
restrictions.add(builder.or(builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")));
if (sandBoxType != null) {
restrictions.add(builder.equal(sandbox.get("sandBox").get("sandboxType"), sandBoxType.getType()));
}
restrictions.add(builder.or(builder.isNull(sandbox.get("sandBox").get("archiveStatus").get("archived").as(String.class)), builder.notEqual(sandbox.get("sandBox").get("archiveStatus").get("archived").as(Character.class), 'Y')));
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<SandBox> query = sandBoxEntityManager.createQuery(criteria);
return query.getResultList();
}
use of org.broadleafcommerce.common.sandbox.domain.SandBox in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxDaoImpl method retrieveChildSandBoxesByParentId.
@Override
public List<SandBox> retrieveChildSandBoxesByParentId(Long parentSandBoxId) {
CriteriaBuilder builder = sandBoxEntityManager.getCriteriaBuilder();
CriteriaQuery<SandBox> criteria = builder.createQuery(SandBox.class);
Root<SandBoxManagementImpl> sandbox = criteria.from(SandBoxManagementImpl.class);
criteria.select(sandbox.get("sandBox").as(SandBox.class));
criteria.where(builder.and(sandbox.get("sandBox").get("parentSandBox").in(parentSandBoxId), builder.or(builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")), builder.or(builder.isNull(sandbox.get("sandBox").get("archiveStatus").get("archived").as(String.class)), builder.notEqual(sandbox.get("sandBox").get("archiveStatus").get("archived").as(Character.class), 'Y'))));
TypedQuery<SandBox> query = sandBoxEntityManager.createQuery(criteria);
return query.getResultList();
}
use of org.broadleafcommerce.common.sandbox.domain.SandBox in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxDaoImpl method merge.
@Override
public SandBox merge(SandBox userSandBox) {
SandBox response = sandBoxEntityManager.merge(userSandBox);
sandBoxEntityManager.flush();
return response;
}
Aggregations