/** * Retrieves existing allowed attribute values based on the specified key * * @param attributeValueListKey the attribute value list key * * @return the allowed attribute values information */ @NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.READ) @Override public AllowedAttributeValuesInformation getAllowedAttributeValues(AttributeValueListKey attributeValueListKey) { // Perform validation and trim of the input parameters. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that a attribute value list exists with the specified name. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Retrieve a list of allowed attribute values. List<AllowedAttributeValueEntity> allowedAttributeValueEntities = allowedAttributeValueDao.getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey); return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, allowedAttributeValueEntities); }
allowedAttributeValueDao.saveAndRefresh(attributeValueListEntity);
/** * Retrieves existing allowed attribute values based on the specified key * * @param attributeValueListKey the attribute value list key * * @return the allowed attribute values information */ @NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.READ) @Override public AllowedAttributeValuesInformation getAllowedAttributeValues(AttributeValueListKey attributeValueListKey) { // Perform validation and trim of the input parameters. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that a attribute value list exists with the specified name. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Retrieve a list of allowed attribute values. List<AllowedAttributeValueEntity> allowedAttributeValueEntities = allowedAttributeValueDao.getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey); return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, allowedAttributeValueEntities); }
allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity); allowedAttributeValueEntity.setAllowedAttributeValue(allowedAttributeValue); allowedAttributeValueDao.saveAndRefresh(allowedAttributeValueEntity); allowedAttributeValueDao.saveAndRefresh(attributeValueListEntity);
@Test public void testGetAllowedAttributeValues() { // Create attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(NAMESPACE_CODE, ATTRIBUTE_VALUE_LIST_NAME); List<String> allowedAttributeValueList = allowedAttributeValueDaoTestHelper.getTestUnsortedAllowedAttributeValues(); // Create and persist a attribute value list key entity. attributeValueListDaoTestHelper.createAttributeValueListEntity(NAMESPACE_CODE, ATTRIBUTE_VALUE_LIST_NAME); // Create and persist a list of allowed attribute values. allowedAttributeValueDaoTestHelper.createAllowedAttributeValueEntities(attributeValueListKey, allowedAttributeValueList); // Get the allowed attribute values for the specified key. List<AllowedAttributeValueEntity> responseEntities = allowedAttributeValueDao.getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey); // Create a list of allowed attribute values. List<String> allowedAttributesResponse = new ArrayList<>(); responseEntities.forEach((responseEntity) -> { allowedAttributesResponse.add(responseEntity.getAllowedAttributeValue()); }); // Validate the response is sorted by allowed attribute values. Collections.sort(allowedAttributeValueList); assertEquals(allowedAttributeValueList, allowedAttributesResponse); } }
allowedAttributeValueDao.saveAndRefresh(attributeValueListEntity);
when(allowedAttributeValueDao.getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey)).thenReturn(allowedAttributeValueEntities); verify(allowedAttributeValueDao).getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey); verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey); verifyNoMoreInteractionsHelper();
allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity); allowedAttributeValueEntity.setAllowedAttributeValue(allowedAttributeValue); allowedAttributeValueDao.saveAndRefresh(allowedAttributeValueEntity); allowedAttributeValueDao.saveAndRefresh(attributeValueListEntity);
when(allowedAttributeValueDao.saveAndRefresh(any(AllowedAttributeValueEntity.class))).thenReturn(allowedAttributeValueEntity); when(alternateKeyHelper.validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE)).thenReturn(ALLOWED_ATTRIBUTE_VALUE); verify(allowedAttributeValueDao, times(1)).saveAndRefresh(any(AllowedAttributeValueEntity.class)); verify(allowedAttributeValueDao, times(1)).saveAndRefresh(any(AttributeValueListEntity.class)); verify(alternateKeyHelper).validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE); verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
when(allowedAttributeValueDao.saveAndRefresh(any(AllowedAttributeValueEntity.class))).thenReturn(allowedAttributeValueEntity); when(alternateKeyHelper.validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE)).thenReturn(ALLOWED_ATTRIBUTE_VALUE); verify(allowedAttributeValueDao).saveAndRefresh(any(AttributeValueListEntity.class)); verify(alternateKeyHelper).validateStringParameter("An", "allowed attribute value", ALLOWED_ATTRIBUTE_VALUE); verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey);
/** * 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; }