@Override public AttributeValueListEntity getAttributeValueListByKey(AttributeValueListKey attributeValueListKey) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<AttributeValueListEntity> criteria = builder.createQuery(AttributeValueListEntity.class); // The criteria root is the attribute value list. Root<AttributeValueListEntity> attributeValueListEntityRoot = criteria.from(AttributeValueListEntity.class); // Join to the other tables we can filter on. Join<AttributeValueListEntity, NamespaceEntity> namespaceEntityJoin = attributeValueListEntityRoot.join(AttributeValueListEntity_.namespace); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), attributeValueListKey.getNamespace().toUpperCase())); predicates.add(builder.equal(builder.upper(attributeValueListEntityRoot.get(AttributeValueListEntity_.name)), attributeValueListKey.getAttributeValueListName().toUpperCase())); // Add all clauses to the query. criteria.select(attributeValueListEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); // Execute the query and return the results. return executeSingleResultQuery(criteria, String .format("Found more than one attribute value list with parameters {namespace=\"%s\", attribute_value_name=\"%s\"}.", attributeValueListKey.getNamespace(), attributeValueListKey.getAttributeValueListName())); }
@Override public AttributeValueListEntity getAttributeValueListByKey(AttributeValueListKey attributeValueListKey) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<AttributeValueListEntity> criteria = builder.createQuery(AttributeValueListEntity.class); // The criteria root is the attribute value list. Root<AttributeValueListEntity> attributeValueListEntityRoot = criteria.from(AttributeValueListEntity.class); // Join to the other tables we can filter on. Join<AttributeValueListEntity, NamespaceEntity> namespaceEntityJoin = attributeValueListEntityRoot.join(AttributeValueListEntity_.namespace); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), attributeValueListKey.getNamespace().toUpperCase())); predicates.add(builder.equal(builder.upper(attributeValueListEntityRoot.get(AttributeValueListEntity_.name)), attributeValueListKey.getAttributeValueListName().toUpperCase())); // Add all clauses to the query. criteria.select(attributeValueListEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))); // Execute the query and return the results. return executeSingleResultQuery(criteria, String .format("Found more than one attribute value list with parameters {namespace=\"%s\", attribute_value_name=\"%s\"}.", attributeValueListKey.getNamespace(), attributeValueListKey.getAttributeValueListName())); }
/** * Gets the attribute value list entity and ensure it exists. * * @param attributeValueListKey the attribute value list key (case insensitive) * * @return the attribute value list entity */ public AttributeValueListEntity getAttributeValueListEntity(AttributeValueListKey attributeValueListKey) { AttributeValueListEntity attributeValueListEntity = attributeValueListDao.getAttributeValueListByKey(attributeValueListKey); if (attributeValueListEntity == null) { throw new ObjectNotFoundException(String .format("Attribute value list with name \"%s\" doesn't exist for namespace \"%s\".", attributeValueListKey.getAttributeValueListName(), attributeValueListKey.getNamespace())); } return attributeValueListEntity; }
attributeValueListKey.getAttributeValueListName().toUpperCase())); predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), attributeValueListKey.getNamespace().toUpperCase()));
/** * Gets the attribute value list entity and ensure it exists. * * @param attributeValueListKey the attribute value list key (case insensitive) * * @return the attribute value list entity */ public AttributeValueListEntity getAttributeValueListEntity(AttributeValueListKey attributeValueListKey) { AttributeValueListEntity attributeValueListEntity = attributeValueListDao.getAttributeValueListByKey(attributeValueListKey); if (attributeValueListEntity == null) { throw new ObjectNotFoundException(String .format("Attribute value list with name \"%s\" doesn't exist for namespace \"%s\".", attributeValueListKey.getAttributeValueListName(), attributeValueListKey.getNamespace())); } return attributeValueListEntity; }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theNamespace; theNamespace = this.getNamespace(); strategy.appendField(locator, this, "namespace", buffer, theNamespace, (this.namespace!= null)); } { String theAttributeValueListName; theAttributeValueListName = this.getAttributeValueListName(); strategy.appendField(locator, this, "attributeValueListName", buffer, theAttributeValueListName, (this.attributeValueListName!= null)); } return buffer; }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theNamespace; theNamespace = this.getNamespace(); strategy.appendField(locator, this, "namespace", buffer, theNamespace, (this.namespace!= null)); } { String theAttributeValueListName; theAttributeValueListName = this.getAttributeValueListName(); strategy.appendField(locator, this, "attributeValueListName", buffer, theAttributeValueListName, (this.attributeValueListName!= null)); } return buffer; }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theNamespace; theNamespace = this.getNamespace(); strategy.appendField(locator, this, "namespace", buffer, theNamespace, (this.namespace!= null)); } { String theAttributeValueListName; theAttributeValueListName = this.getAttributeValueListName(); strategy.appendField(locator, this, "attributeValueListName", buffer, theAttributeValueListName, (this.attributeValueListName!= null)); } return buffer; }
/** * Validates an attribute value list key. * * @param attributeValueListKey the attribute value list key */ public void validateAttributeValueListKey(AttributeValueListKey attributeValueListKey) { // Validate. Assert.notNull(attributeValueListKey, "An attribute value list key must be specified."); attributeValueListKey.setNamespace(alternateKeyHelper.validateStringParameter("namespace", attributeValueListKey.getNamespace())); attributeValueListKey.setAttributeValueListName( alternateKeyHelper.validateStringParameter("An", "attribute value list name", attributeValueListKey.getAttributeValueListName())); } }
/** * Validates an attribute value list key. * * @param attributeValueListKey the attribute value list key */ public void validateAttributeValueListKey(AttributeValueListKey attributeValueListKey) { // Validate. Assert.notNull(attributeValueListKey, "An attribute value list key must be specified."); attributeValueListKey.setNamespace(alternateKeyHelper.validateStringParameter("namespace", attributeValueListKey.getNamespace())); attributeValueListKey.setAttributeValueListName( alternateKeyHelper.validateStringParameter("An", "attribute value list name", attributeValueListKey.getAttributeValueListName())); } }
public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) { if ((object == null)||(this.getClass()!= object.getClass())) { return false; } if (this == object) { return true; } final AttributeValueListKey that = ((AttributeValueListKey) object); { String lhsNamespace; lhsNamespace = this.getNamespace(); String rhsNamespace; rhsNamespace = that.getNamespace(); if (!strategy.equals(LocatorUtils.property(thisLocator, "namespace", lhsNamespace), LocatorUtils.property(thatLocator, "namespace", rhsNamespace), lhsNamespace, rhsNamespace, (this.namespace!= null), (that.namespace!= null))) { return false; } } { String lhsAttributeValueListName; lhsAttributeValueListName = this.getAttributeValueListName(); String rhsAttributeValueListName; rhsAttributeValueListName = that.getAttributeValueListName(); if (!strategy.equals(LocatorUtils.property(thisLocator, "attributeValueListName", lhsAttributeValueListName), LocatorUtils.property(thatLocator, "attributeValueListName", rhsAttributeValueListName), lhsAttributeValueListName, rhsAttributeValueListName, (this.attributeValueListName!= null), (that.attributeValueListName!= null))) { return false; } } return true; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theNamespace; theNamespace = this.getNamespace(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "namespace", theNamespace), currentHashCode, theNamespace, (this.namespace!= null)); } { String theAttributeValueListName; theAttributeValueListName = this.getAttributeValueListName(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "attributeValueListName", theAttributeValueListName), currentHashCode, theAttributeValueListName, (this.attributeValueListName!= null)); } return currentHashCode; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theNamespace; theNamespace = this.getNamespace(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "namespace", theNamespace), currentHashCode, theNamespace, (this.namespace!= null)); } { String theAttributeValueListName; theAttributeValueListName = this.getAttributeValueListName(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "attributeValueListName", theAttributeValueListName), currentHashCode, theAttributeValueListName, (this.attributeValueListName!= null)); } return currentHashCode; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theNamespace; theNamespace = this.getNamespace(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "namespace", theNamespace), currentHashCode, theNamespace, (this.namespace!= null)); } { String theAttributeValueListName; theAttributeValueListName = this.getAttributeValueListName(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "attributeValueListName", theAttributeValueListName), currentHashCode, theAttributeValueListName, (this.attributeValueListName!= null)); } return currentHashCode; }
/** * Creates and persists a new attribute value list entity from the request information. * * @param request the request * @param namespaceEntity the namespace * * @return the newly created attribute value list entity */ private AttributeValueListEntity createAttributeValueListEntity(AttributeValueListCreateRequest request, NamespaceEntity namespaceEntity) { // Create a new entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(request.getAttributeValueListKey().getAttributeValueListName()); // Persist and return the newly created entity. return attributeValueListDao.saveAndRefresh(attributeValueListEntity); } }
/** * Creates and persists a new attribute value list entity from the request information. * * @param request the request * @param namespaceEntity the namespace * * @return the newly created attribute value list entity */ private AttributeValueListEntity createAttributeValueListEntity(AttributeValueListCreateRequest request, NamespaceEntity namespaceEntity) { // Create a new entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(request.getAttributeValueListKey().getAttributeValueListName()); // Persist and return the newly created entity. return attributeValueListDao.saveAndRefresh(attributeValueListEntity); } }
@Test public void testGetAttributeValueListKeys() { // Create several attribute value list keys in random order. List<AttributeValueListKey> attributeValueListKeys = Arrays .asList(new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME_2), new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE_2, ATTRIBUTE_VALUE_LIST_NAME_2), new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE_2, ATTRIBUTE_VALUE_LIST_NAME), new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME)); // Create and persist attribute value list entities. for (AttributeValueListKey attributeValueListKey : attributeValueListKeys) { attributeValueListDaoTestHelper .createAttributeValueListEntity(attributeValueListKey.getNamespace(), attributeValueListKey.getAttributeValueListName()); } // Retrieve a list of attribute value list keys. assertEquals(Arrays.asList(attributeValueListKeys.get(3), attributeValueListKeys.get(0)), attributeValueListDao.getAttributeValueLists(Arrays.asList(ATTRIBUTE_VALUE_LIST_NAMESPACE))); // Test case sensitivity. assertEquals(new ArrayList<>(), attributeValueListDao.getAttributeValueLists(Arrays.asList(ATTRIBUTE_VALUE_LIST_NAMESPACE.toUpperCase()))); assertEquals(new ArrayList<>(), attributeValueListDao.getAttributeValueLists(Arrays.asList(ATTRIBUTE_VALUE_LIST_NAMESPACE.toLowerCase()))); // Retrieve the list of keys for all attribute value lists registered in the system. assertEquals(Arrays.asList(attributeValueListKeys.get(3), attributeValueListKeys.get(0), attributeValueListKeys.get(2), attributeValueListKeys.get(1)), attributeValueListDao.getAttributeValueLists(null)); } }
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public AttributeValueList createAttributeValueList(AttributeValueListCreateRequest request) { // Validate and trim the request parameters. attributeValueListHelper.validateAttributeValueListCreateRequest(request); // Get the attribute value list key. AttributeValueListKey attributeValueListKey = request.getAttributeValueListKey(); // Retrieve the namespace entity and validate it exists. NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getAttributeValueListKey().getNamespace()); // Validate the attribute value list does not already exist. if (attributeValueListDao.getAttributeValueListByKey(request.getAttributeValueListKey()) != null) { throw new AlreadyExistsException(String .format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", attributeValueListKey.getAttributeValueListName(), attributeValueListKey.getNamespace())); } // Create and persist a new attribute value list entity from the request information. AttributeValueListEntity attributeValueListEntity = createAttributeValueListEntity(request, namespaceEntity); // Create and return the attribute value list object from the persisted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public AttributeValueList createAttributeValueList(AttributeValueListCreateRequest request) { // Validate and trim the request parameters. attributeValueListHelper.validateAttributeValueListCreateRequest(request); // Get the attribute value list key. AttributeValueListKey attributeValueListKey = request.getAttributeValueListKey(); // Retrieve the namespace entity and validate it exists. NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getAttributeValueListKey().getNamespace()); // Validate the attribute value list does not already exist. if (attributeValueListDao.getAttributeValueListByKey(request.getAttributeValueListKey()) != null) { throw new AlreadyExistsException(String .format("Unable to create attribute value list with name \"%s\" because it already exists for namespace \"%s\".", attributeValueListKey.getAttributeValueListName(), attributeValueListKey.getNamespace())); } // Create and persist a new attribute value list entity from the request information. AttributeValueListEntity attributeValueListEntity = createAttributeValueListEntity(request, namespaceEntity); // Create and return the attribute value list object from the persisted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
/** * Returns a list of test allowed attribute value entities. * * @return the list of allowed attribute value entities */ public List<AllowedAttributeValueEntity> createAllowedAttributeValueEntities(AttributeValueListKey attributeValueListKey, List<String> allowedAttributeValues) { AttributeValueListEntity attributeValueListEntity = attributeValueListDao.getAttributeValueListByKey(attributeValueListKey); if (attributeValueListEntity == null) { attributeValueListEntity = attributeValueListDaoTestHelper.createAttributeValueListEntity(attributeValueListKey.getNamespace(), attributeValueListKey.getAttributeValueListName()); } List<AllowedAttributeValueEntity> allowedAttributeValueEntities = new ArrayList<>(); for (String allowedAttributeValue : allowedAttributeValues) { AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity(); allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity); allowedAttributeValueEntity.setAllowedAttributeValue(allowedAttributeValue); allowedAttributeValueEntities.add(allowedAttributeValueDao.saveAndRefresh(allowedAttributeValueEntity)); } return allowedAttributeValueEntities; }