protected String getProjectId() { return userContext != null ? userContext.getProjectId() : null; }
@Override public SequenceWorkflowEntryRepository.Item preSave(SequenceWorkflowEntryRepository.Item item, Session session){ //The collectionSequence on the entry is only used for filter/sorting, remove before updating. if(item.sequenceWorkflowEntry.collectionSequence!=null){ item.sequenceWorkflowEntry.collectionSequence = null; } if (!Strings.isNullOrEmpty(userContext.getProjectId())) { return item; } throw new RuntimeException("Unable to save item - projectId is null"); }
@Override protected Collection<NameValuePair> getApiParams() { Collection<NameValuePair> params = new ArrayList<>(1); params.add(new BasicNameValuePair("project_id", context.getProjectId())); return params; } }
@Override protected Collection<NameValuePair> getApiParams() { Collection<NameValuePair> params = new ArrayList<>(1); params.add(new BasicNameValuePair("project_id", context.getProjectId())); return params; }
@Override protected Collection<NameValuePair> getApiParams() { Collection<NameValuePair> params = new ArrayList<>(1); params.add(new BasicNameValuePair("project_id", context.getProjectId())); return params; } }
@Override protected Collection<NameValuePair> getApiParams() { Collection<NameValuePair> params = new ArrayList<>(1); params.add(new BasicNameValuePair("project_id", context.getProjectId())); return params; } }
@Override protected Collection<NameValuePair> getApiParams() { Collection<NameValuePair> params = new ArrayList<>(1); params.add(new BasicNameValuePair("project_id", context.getProjectId())); return params; } }
@Override protected Collection<NameValuePair> getApiParams() { Collection<NameValuePair> params = new ArrayList<>(1); params.add(new BasicNameValuePair("project_id", context.getProjectId())); return params; } }
private String getProjectIdAllowingForAdminApi( ){ // Get the thread scoped admin context. AdminUserContext adminUserContext = applicationContext.getBean(AdminUserContext.class); if ( adminUserContext != null && adminUserContext.isAllowAdministration() ) { return null; } return userContext.getProjectId(); } }
protected <R extends T> R preSave(T item, Session session){ // Check in preSave that we are allowed to add items with a projectId of null. // This is only allowed for certain types, when api.admin.basedata=true if (!Strings.isNullOrEmpty(userContext.getProjectId())) { return (R)item; } // check is the adminUserContext allowing administration of base data. AdminUserContext adminUserContext = applicationContext.getBean(AdminUserContext.class); if ( adminUserContext != null && adminUserContext.isAllowAdministration() ) { return (R) item; } throw new RuntimeException("Unable to save item - projectId is null"); }
@Override protected void delete(Session session, Long id) { String hql = "delete from " + objectName + " where id= :id and collection.projectId= :projectId"; int i = session.createQuery(hql) .setLong("id", id) .setString("projectId", userContext.getProjectId()) .executeUpdate(); if(i == 0){ throw new RuntimeException("Item could not be deleted"); } }
private void deleteSequenceWorkflowEntries(Session session, Long sequenceWorkflowId) { // ensure any entries already in the DB, are deleted, we recreate this list // each time, to ensure correct ordering. String hql = "delete from SequenceWorkflowEntryRepository$Item where sequenceWorkflowId= :sequenceWorkflowId and projectId= :projectId"; session.createQuery(hql) .setLong("sequenceWorkflowId", sequenceWorkflowId) .setString("projectId", userContext.getProjectId()) .executeUpdate(); }
@Override protected Criteria createThisObjectsBaseCriteria(Session session, Filter filter ) { // by default we use the type parameter class of this repository. // if we have a filter, it may be that we need the real concrete class which is // used as a discriminator at the backend. Class<?> criteriaClass = ( filter == null) ? typeParameterClass : AnnotationHelper.getRealRequestClassType(typeParameterClass, filter); return session.createCriteria(typeParameterClass) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.or( Restrictions.eq("collection.projectId", userContext.getProjectId()), Restrictions.isNull("collection.projectId"))); }
@Override protected void delete(Session session, Long id) { Item item = retrieveSingleItem(session, id); //noinspection JpaQlInspection String hql = "delete from " + objectName + " where id= :id and projectId= :projectId"; int i = session.createQuery(hql) .setLong("id", id) .setString("projectId", userContext.getProjectId()) .executeUpdate(); if (i == 0) { throw new RuntimeException("Item could not be deleted"); } }
@Override public void delete(ExecutionContext executionContext, Long id) { Session session = getSession(executionContext); String hql = "delete from Condition where id= :conditionId and projectId= :projectId"; session.createQuery(hql).setLong("conditionId", id).setString("projectId", userContext.getProjectId()).executeUpdate(); }
@Override public void deleteAll(ExecutionContext executionContext, Long sequenceWorkflowId) { Session session = getSession(executionContext); String hql = "delete from SequenceWorkflowEntryRepository$Item where sequenceWorkflowId= :sequenceWorkflowId and projectId= :projectId"; int i = session.createQuery(hql) .setLong("sequenceWorkflowId", sequenceWorkflowId) .setString("projectId", userContext.getProjectId()) .executeUpdate(); }
@Override public void deleteAll(ExecutionContext executionContext, Long collectionSequenceId) { Session session = getSession(executionContext); String hql = "delete from CollectionSequenceEntryRepository$Item where collectionSequenceId= :collectionSequenceId and projectId= :projectId"; int i = session.createQuery(hql) .setLong("collectionSequenceId", collectionSequenceId) .setString("projectId", userContext.getProjectId()) .executeUpdate(); }
@Override public void deleteChildren(ExecutionContext executionContext, Long id) { Session session = getSession(executionContext); String hql = "delete from Condition where parentConditionId= :parentConditionId and projectId= :projectId"; session.createQuery(hql).setLong("parentConditionId", id).setString("projectId", userContext.getProjectId()).executeUpdate(); }
@Override public void dissociatePolicyFromCollection(ExecutionContext executionContext, long policyId, long collectionId) { Session session = getSession(executionContext); String hql = "delete from HibernateCollectionPolicy where collectionId= :collectionId and policyId=:policyId and projectId= :projectId"; int i = session.createQuery(hql) .setLong("collectionId", collectionId) .setLong("policyId", policyId) .setString("projectId", userContext.getProjectId()) .executeUpdate(); if(i == 0){ throw new RuntimeException("Item could not be deleted"); } }
@Override protected Criteria createThisObjectsBaseCriteria(Session session, Filter filter) { // by default we use the type parameter class of this repository. // if we have a filter, it may be that we need the real concrete class which is // used as a discriminator at the backend. Class<?> criteriaClass = (filter == null) ? typeParameterClass : AnnotationHelper.getRealRequestClassType(typeParameterClass, filter); return session.createCriteria(criteriaClass) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.or( Restrictions.eqOrIsNull("projectId", userContext.getProjectId()), Restrictions.isNull("projectId") )); }