Creating history for item

If you want create history for item look like backoffice, you can use below example.
[code lang=”java”]public void updateConsignmentStatus(String userUid, ConsignmentModel consignment, ConsignmentStatus status) {
Map originals = new HashMap();
originals.put(ConsignmentModel.STATUS, consignment.getStatus());

consignment.setStatus(status);

Map news = new HashMap();
news.put(ConsignmentModel.STATUS, consignment.getStatus());

final SavedValues savedValues = JaloConnection.getInstance().logItemModification(consignment.getPk(), news, originals, false);
savedValues.setUser(UserManager.getInstance().getUserByLogin(userUid));
modelService.saveAll();
}[/code]

Creating,updating or deleting other items in interceptor

[code lang=”java”]public class MyCustomerPrepareInterceptor implements PrepareInterceptor {
private static final Logger LOG = Logger.getLogger(MyCustomerPrepareInterceptor.class);

@Override
public void onPrepare(CustomerModel customerModel, InterceptorContext interceptorContext) throws InterceptorException {


final MyItemModel myItem = interceptorContext.getModelService().create(MyItemModel.class);
interceptorContext.registerElement(myItem);
//interceptorContext.registerElementFor(myItem, PersistenceOperation.DELETE);

}
}[/code]

Using separate file for different class logging

Below example logging flexiblesearch class to separate file with time based trigger policy. Also we can add rollover strategy for removing old files.

[code]log4j2.appender.FlexlogAppender.type=RollingFile log4j2.appender.FlexlogAppender.name=FlexlogAppender
log4j2.appender.FlexlogAppender.fileName=${HYBRIS_LOG_DIR}/Flexlog.log
log4j2.appender.FlexlogAppender.filePattern=${HYBRIS_LOG_DIR}/Flexlog.log-%d{yyyy-MM-dd}.log
log4j2.appender.FlexlogAppender.ImmediateFlush=true log4j2.appender.FlexlogAppender.layout.type=PatternLayout
log4j2.appender.FlexlogAppender.layout.pattern=%m%n log4j2.appender.FlexlogAppender.policies.type = Policies
log4j2.appender.FlexlogAppender.policies.time.type = TimeBasedTriggeringPolicy log4j2.appender.FlexlogAppender.policies.time.interval = 1000000
log4j2.appender.FlexlogAppender.policies.time.modulate = true log4j2.logger.flexible.name = de.hybris.platform.jalo.flexiblesearch
log4j2.logger.flexible.level = DEBUG log4j2.logger.flexible.appenderRef.stdout.ref = FlexlogAppender log4j2.logger.flexible.additivity = false[/code]

Update object private property with groovy

You can update private field an object with below sample code.

[code lang=”java”]def myBean = spring.getBean(“myBean”);

def f = myBean.getClass().getDeclaredField(“myField”);
f.setAccessible(true);
f.set(myBean, “new string value”);[/code]