@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.READ) @Override public AttributeValueList getAttributeValueList(AttributeValueListKey attributeValueListKey) { // Perform validation and trim. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that an attribute value list already exists with the specified key. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Create and return the attribute value list object from the deleted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.READ) @Override public AttributeValueList getAttributeValueList(AttributeValueListKey attributeValueListKey) { // Perform validation and trim. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that an attribute value list already exists with the specified key. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Create and return the attribute value list object from the deleted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override public AttributeValueList deleteAttributeValueList(AttributeValueListKey attributeValueListKey) { // Perform validation and trim. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that an attribute value list already exists with the specified key. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Delete the attribute value list. attributeValueListDao.delete(attributeValueListEntity); // Create and return the attribute value list object from the deleted entity. return attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity); }
@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE) @Override public AttributeValueList deleteAttributeValueList(AttributeValueListKey attributeValueListKey) { // Perform validation and trim. attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey); // Retrieve and ensure that an attribute value list already exists with the specified key. AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey); // Delete the attribute value list. attributeValueListDao.delete(attributeValueListEntity); // Create and return the attribute value list object from the deleted 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); }
@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); }
when(attributeValueListDao.getAttributeValueListByKey(attributeValueListKey)).thenReturn(null); when(attributeValueListDao.saveAndRefresh(any(AttributeValueListEntity.class))).thenReturn(attributeValueListEntity); when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod(); verify(attributeValueListDao).getAttributeValueListByKey(attributeValueListKey); verify(attributeValueListDao).saveAndRefresh(any(AttributeValueListEntity.class)); verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity); verifyNoMoreInteractionsHelper();
@Test public void testDeleteAttributeValueList() { // Create an attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // Create a namespace entity. NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE); // Create an attribute value list entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); // Mock calls to external methods. when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity); when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod(); // Call the method under test. AttributeValueList result = attributeValueListService.deleteAttributeValueList(attributeValueListKey); // Verify the external calls. verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey); verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey); verify(attributeValueListDao).delete(attributeValueListEntity); verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity); verifyNoMoreInteractionsHelper(); // Validate the result. assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result); }
@Test public void testGetAttributeValueList() { // Create an attribute value list key. AttributeValueListKey attributeValueListKey = new AttributeValueListKey(ATTRIBUTE_VALUE_LIST_NAMESPACE, ATTRIBUTE_VALUE_LIST_NAME); // Create a namespace entity. NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode(ATTRIBUTE_VALUE_LIST_NAMESPACE); // Create an attribute value list entity. AttributeValueListEntity attributeValueListEntity = new AttributeValueListEntity(); attributeValueListEntity.setId(ATTRIBUTE_VALUE_LIST_ID); attributeValueListEntity.setNamespace(namespaceEntity); attributeValueListEntity.setName(ATTRIBUTE_VALUE_LIST_NAME); // Mock calls to external methods. when(attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey)).thenReturn(attributeValueListEntity); when(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)).thenCallRealMethod(); // Call the method under test. AttributeValueList result = attributeValueListService.getAttributeValueList(attributeValueListKey); // Verify the external calls. verify(attributeValueListHelper).validateAttributeValueListKey(attributeValueListKey); verify(attributeValueListDaoHelper).getAttributeValueListEntity(attributeValueListKey); verify(attributeValueListDaoHelper).createAttributeValueListFromEntity(attributeValueListEntity); verifyNoMoreInteractionsHelper(); // Validate the result. assertEquals(new AttributeValueList(ATTRIBUTE_VALUE_LIST_ID, attributeValueListKey), result); }
private GlobalAttributeDefinition createGlobalAttributeDefinitionFromEntity(GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity) { GlobalAttributeDefinition globalAttributeDefinition = new GlobalAttributeDefinition(); globalAttributeDefinition.setId(globalAttributeDefinitionEntity.getId()); GlobalAttributeDefinitionKey globalAttributeDefinitionKey = new GlobalAttributeDefinitionKey(); globalAttributeDefinitionKey .setGlobalAttributeDefinitionLevel(globalAttributeDefinitionEntity.getGlobalAttributeDefinitionLevel().getGlobalAttributeDefinitionLevel()); globalAttributeDefinitionKey.setGlobalAttributeDefinitionName(globalAttributeDefinitionEntity.getGlobalAttributeDefinitionName()); globalAttributeDefinition.setGlobalAttributeDefinitionKey(globalAttributeDefinitionKey); AttributeValueListEntity attributeValueListEntity = globalAttributeDefinitionEntity.getAttributeValueList(); if (attributeValueListEntity != null) { globalAttributeDefinition.setAttributeValueList(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)); } return globalAttributeDefinition; }
private GlobalAttributeDefinition createGlobalAttributeDefinitionFromEntity(GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity) { GlobalAttributeDefinition globalAttributeDefinition = new GlobalAttributeDefinition(); globalAttributeDefinition.setId(globalAttributeDefinitionEntity.getId()); GlobalAttributeDefinitionKey globalAttributeDefinitionKey = new GlobalAttributeDefinitionKey(); globalAttributeDefinitionKey .setGlobalAttributeDefinitionLevel(globalAttributeDefinitionEntity.getGlobalAttributeDefinitionLevel().getGlobalAttributeDefinitionLevel()); globalAttributeDefinitionKey.setGlobalAttributeDefinitionName(globalAttributeDefinitionEntity.getGlobalAttributeDefinitionName()); globalAttributeDefinition.setGlobalAttributeDefinitionKey(globalAttributeDefinitionKey); AttributeValueListEntity attributeValueListEntity = globalAttributeDefinitionEntity.getAttributeValueList(); if (attributeValueListEntity != null) { globalAttributeDefinition.setAttributeValueList(attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)); } return globalAttributeDefinition; }
@Test public void testGetGlobalAttributeDefinition() { // Create a global attribute definition key. GlobalAttributeDefinitionKey globalAttributeDefinitionKey = new GlobalAttributeDefinitionKey(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME); // Create a global attribute definition entity. GlobalAttributeDefinitionEntity globalAttributeDefinitionEntity = globalAttributeDefinitionDaoTestHelper.createGlobalAttributeDefinitionEntity(GLOBAL_ATTRIBUTE_DEFINITON_LEVEL, GLOBAL_ATTRIBUTE_DEFINITON_NAME); AttributeValueListEntity attributeValueListEntity = attributeValueListDaoTestHelper.createAttributeValueListEntity("namespace_1", "list_1"); globalAttributeDefinitionEntity.setAttributeValueList(attributeValueListEntity); // Mock calls to external methods. when(globalAttributeDefinitionDaoHelper.getGlobalAttributeDefinitionEntity(globalAttributeDefinitionKey)).thenReturn(globalAttributeDefinitionEntity); // Call the method under test. GlobalAttributeDefinition response = globalAttributeDefinitionService.getGlobalAttributeDefinition(globalAttributeDefinitionKey); // Verify the external calls. verify(globalAttributeDefinitionHelper).validateGlobalAttributeDefinitionKey(globalAttributeDefinitionKey); verify(globalAttributeDefinitionDaoHelper).getGlobalAttributeDefinitionEntity(globalAttributeDefinitionKey); verifyNoMoreInteractionsHelper(); // Validate. assertEquals(new GlobalAttributeDefinition(response.getId(), globalAttributeDefinitionKey, attributeValueListDaoHelper.createAttributeValueListFromEntity(attributeValueListEntity)), response); }