I used following code to create a cart and add one cartEntry inside this CartModel:
final CartModel cartModel = cartFactory.createCart() ;
OrderEntryModel orderEntryModel = new OrderEntryModel();
List<AbstractOrderEntryModel> entryModel = new ArrayList<>();
final ProductModel product = productService.getProductForCode(productCode); // came from another method
orderEntryModel.setProduct(product);
entryModel.add(orderEntryModel);
cartModel.setEntries(entryModel);
cartModel.setUser(userService.getCurrentUser());
cartService.setSessionCart(cartModel);
When I try to get this cart from session, apply this cart, and pass this cart to next another OOTB method, I get the following exception:
DefultAbstractOrderEntryPreparer#1090ef7e]: unexpected preparer error: null] with root cause
java.lang.NullPointerException
at de.hybris.platform.order.interceptors.DefaultAbstractOrderEntryPreparer.onPrepare(DefaultAbstractOrderEntryPreparer.java:97)
After debugging, I got to know that this issue occurs because I am adding order entries in a different way than what we used in a normal checkout flow (first code block , third last line) .
So, is there any OOTB method or any other way to create an orderEntry and add it to a newly-created cart?
I checked for normal cart created during Checkout flow, and this issue doesn't happen. So, I came to a conclusion that this occurs because of following code from the first code block:
OrderEntryModel orderEntryModel = new OrderEntryModel();
List<AbstractOrderEntryModel> entryModel = new ArrayList<>();
final ProductModel product = productService.getProductForCode(productCode); // came from another method
orderEntryModel.setProduct(product);
entryModel.add(orderEntryModel);
cartModel.setEntries(entryModel);
There is a standard service called cartService, that as addNewEntry method.
final CartModel cartModel = cartFactory.createCart();
final ProductModel product = productService.getProductForCode(productCode); // came from another method
getCartService().addNewEntry(cartModel, product, 1, null);
cartModel.setUser(userService.getCurrentUser());
cartService.setSessionCart(cartModel);
Related
I want to get the name of the end event in which my process instance ended. I am using Activiti version 7 (spring boot starter of activit). Could anyone help on this?
Hi I also had similar question, and I know this is bit old now, but still ...
You can use HistoryService to get finished process ( presuming you have some id of it )
#Autowired
private HistoryService historyService;
Please consider my code sniplet, which will actually end process due to end of path
Map<String, Object> params = new HashMap<>(); // Some params
Task task = taskService.createTaskQuery()
.processInstanceId(processId)
.singleResult();
taskService.complete(task.getId(), params); //params optional, this ends whole process
List<HistoricVariableInstance> allVars = historyService
.createHistoricVariableInstanceQuery()
.processInstanceId(navTask.getProcessId())
.list();
//return to user all filled in forms etc.
HistoricProcessInstance historicProcess = historyService.createHistoricProcessInstanceQuery().processInstanceId(navTask.getProcessId()).singleResult();
String endId = historicProcess.getEndActivityId(); //This returns ID where your process ended
If id of ending activity is not enough you can go with more digging:
String procDefId = historicProcess.getProcessDefinitionId()
FlowElement flowEl = repositoryService.getBpmnModel(procDefId).getMainProcess().getFlowElements()
.stream()
.filter(flowElement -> flowElement.getId().equals("endId"))
.findFirst()
.orElseThrow(IllegalStateException::new)
flowEl.getName() //your name and other stuff you need
One bottom note: In my case history was not persisted and had to update application properties with spring.activiti.historyLevel=activity and spring.activiti.dbHistoryUsed=true
I'm trying to add links to every record in my databse, as I am trying to implement the HATEOAS concept. However, I have been experiencing some trouble with this. I tried following this guide https://spring.io/guides/gs/rest-hateoas/. But with no success. How and where should I write the code for adding links? Because it doesn't seem to work when I try to write it in my controller method because withSelfRel() is undefined.
Basically I'm trying to add a link to every account made in my database.
//Create account
#RequestMapping(value="/accounts", method = RequestMethod.POST)
public ResponseEntity<?> accountInsert(#RequestBody Account account) {
account = new Account(account.getFirstName(), account.getLastName(), account.getEmail(), account.getPassword(), account.getBirthDate(), account.getActivities(), account.getFriends());
accountRepository.save(account);
//account.add(linkTo(methodOn(AccountController.class, accountInsert(account)).withSelfRel())); /// HERE IS MY TRY
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(ServletUriComponentsBuilder.fromCurrentRequest().build().toUri());
return new ResponseEntity<>(null, httpHeaders, HttpStatus.CREATED);
}
Thank you in advance!
you can not use method inside the same one
Try this :-
Link self=linkTo(AccountController.class).slash(account.getId()).withSelfRel();
Or you can refer from given link
I've got an hosted instance of SugarCRM 6.5 CE, and one of the requirements I have to fulfil is to display some information--contact phone number, contact email address--of the parent record in an associated task/activity record.
All I found so far was pointing towards the creation of a logic hook for pulling the contact information from the parent record (Contacts) and display these in custom fields in the child record (Tasks).
Following some instructions and examples found I came up with the following as outlined below.
Under "custom/modules/Tasks" I've create a file called "logic_hooks.php"
<?php// $Id$
$hook_version = 1;
$hook_array = Array();
// debug
$GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
$GLOBALS['log']->debug("Task: logic hook invoked");
// position, file, function
$hook_array['after_retrieve'] = Array();
$hook_array['after_retrieve'][] = Array('1', 'contact_info', 'custom/modules/Tasks/hooks/contact_info.php','contact_info_class', 'contact_info_method');
?>
and under "custom/modules/Tasks/hooks" I've create a file called "contact_info.phplogic_hooks.php"
<?php
class contact_info_class {
// retrieve contact information from parent record
function contact_info_method($bean, $event, $arguments) {
// debug
$GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
$GLOBALS['log']->debug("Tasks: contact_info_method called for event ".$event . "(BeanID: " . $bean->id . ")");
// fetch data
if ($bean->fetched_row['id'] != $bean->id) {
// load Task
//$bean = BeanFactory::getBean('Tasks', $id);
// check if relationship is loaded
//if ($bean->load_relationship('contact_tasks_parent'))
if ($bean->load_relationship('contact_tasks')) {
// fetch related beans
//$relatedBeans = $bean->contact_tasks_parent->getBeans();
$relatedBeans = $bean->contact_tasks->getBeans();
$parentBean = false;
if (!empty($relatedBeans)) {
// order the results
reset($relatedBeans);
// first record in the list is the parent
$parentBean = current($relatedBeans);
// retrieve data from parent bean
$bean->contact_phone_c = $parentBean->phone_work
$bean->contact_primary_email_c = $parentBean->email1
}
}
}
} // contact_info_method
} // contact_info_class
?>
With this hook in place I can create new tasks without any problem at all, but when opening up an existing one, I'm receiving a message, reading
There was an error processing your request, please try again at a later time.
Being completely new to SugarCRM (btw. 6.5.20 CE it is I'm dealing with), I've got not the faintest idea as what is going wrong here.
I also cannot find any of the debug messages which are supposed to be written somewhere to.
--Sil68
The "contact_info.phplogic_hooks.php" file should be in the same folder as logic_hooks.php (custom/modules/< module-name>). And there's no need to name it that way (in fact I think it might cause problems). Try naming it just contact_info.php and changing the path given in the logic_hooks.php file to custom/modules/Tasks/contact_info.php.
As for where you can find the error log, assuming you're using apache for your web server (since you didn't specify) for linux/OS X, the error log is located at
/var/log/apache2/error.log
or
/var/log/apache2/error_log
In windows it'll be in
'C:\Program Files\Apache Software Foundation\Apache2.2\logs'.
Now that you know where the error log is, you can put
error_log('some helpful message');
inside your contact_info.php file and see which messages (if any) get sent to the error log. This can tell you if it even starts the logic hook and if so, how far it gets through the logic hook
I need to store dynamically created xmldatasource for menu in cache based on the login user. The below code is returning the same data for all the users since i did not mentioned the login user. where do I need to mention the login name while add a cache? also i want to reset or remove the cache while add a new site from event receiver since sitemap has to recreate.
private static object _lock = new object();
public XmlDocument CacheData()
{
XmlDocument item;
lock (_lock)
{
item = (XmlDocument)Cache["SiteMapCache"];
if (item == null)
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
SPWebApplication webapp = site.WebApplication;
item = GenerateMenu(webapp);
}
Cache.Add("SiteMapCache",
item, null,
DateTime.Now.AddMinutes(1),
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Default,
null);
}
return item;
}
}
one Not sure why you would be doing this. As if you built a Sharepoint OOTB publishing site, additional sub site's which a user had access to would appear. If you went down the root of caching each you could end up with loads of entries in the cache, as each one would need to be different.
Else add the USERName to the CacheKey name.
Then change your code so it first checks to see if the "SiteMapCache"+Spcontext.Current.Web.CurrentUser.name is null, if it is fetch it and store it as cache.
You will need another cached item, to store a list of users who have been added to the cache.
Then if a new site is created, loop through each one and set cached item to null.
I am trying to create a new contact using Dynamic Entity. The sample i found in CRM SDK had this code.
// Set the properties of the contact using property objects.
StringProperty firstname = new StringProperty();
firstname.Name = "firstname";
firstname.Value = "Jesper";
StringProperty lastname = new StringProperty();
lastname.Name = "lastname";
lastname.Value = "Aaberg";
// Create the DynamicEntity object.
DynamicEntity contactEntity = new DynamicEntity();
// Set the name of the entity type.
contactEntity.Name = EntityName.contact.ToString();
// Set the properties of the contact.
contactEntity.Properties = new Property[] {firstname, lastname};
In my code i have the following implementation.
StringProperty sp_Field1 = new StringProperty("Field1","Value1");
StringProperty sp_Field2 = new StringProperty("Field2","Value1");
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the DynamicEntity object.
DynamicEntity contactEntity = new DynamicEntity();
// Set the name of the entity type.
contactEntity.Name = EntityName.contact.ToString();
// Set the properties of the contact.
contactEntity.Properties = new Property[] {sp_Field1,sp_Field2};
I don't see much differences in the code. In the examples i found in the internet i have the same implementation as i found in SDK. But if i run the same i get the following error
CS0029: Cannot implicitly convert type 'Microsoft.Crm.Sdk.StringProperty' to 'Microsoft.Crm.Sdk.PropertyCollection'
I tried created a new variable of type PropertyCollection(one that belongs in mscrm namespace) and added the stringpropertys into that and passed it to the entity.
Microsoft.Crm.Sdk.PropertyCollection propTest = new Microsoft.Crm.Sdk.PropertyCollection();
propTest.Add(sp_SSNNo);
propTest.Add(sp_FirstName);
contactEntity.Properties = new Property[] {propTest};
This gave me the following error
CS0029: Cannot implicitly convert type 'Microsoft.Crm.Sdk.PropertyCollection' to 'Microsoft.Crm.Sdk.Property'
I am sure its a minor typecasting error but i am not able to figure out where the error is. And moreover, even if it was a typecasting error why is it working for all the samples given in the internet and not for me. I tried getting the code sample to run but i am encountering the same conversion error. Please let me know if you need more info on this, any help on this would be appreciated.
Here is an article from Microsoft that makes an attempt to discuss this topic:
http://community.dynamics.com/blogs/cscrmblog/archive/2008/06/23/web-services-amp-dlls-or-what-s-up-with-all-the-duplicate-classes.aspx
This is not a bug that you are running into but more of a difference in design between the way the two assemblies work and what they are designed to do.
If you want to continue to use the Microsoft.Crm.Sdk.dll you should be able to accomplish your goal with the following...
StringProperty sp_Field1 = new StringProperty("Field1","Value1");
StringProperty sp_Field2 = new StringProperty("Field2","Value1");
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the DynamicEntity object.
DynamicEntity contactEntity = new DynamicEntity();
// Set the name of the entity type.
contactEntity.Name = EntityName.contact.ToString();
// Set the properties of the contact.
PropertyCollection properties = new PropertyCollection();
properties.Add(sp_Field1);
contactEntity.Properties = properties;
Thanks SaaS Developer, that code is working fine now. One more way of doing it would be to directly add the StringProperty to the entity property collection.
contactEntity.Properties.Add(sp_SSNNo);
Thanks again for replying :)
I believe the issue is that you are referencing the dynamic entity class in the Microsoft.Crm.Sdk assembly. The sample in the SDK is using a reference to the CRM web service. This can get confusing as both assemblies contain many of the same types, however they are different.