我想创建自定义CronJob。我跟着this tutorial,但不幸的是,我无法在Backoffice中看到我的工作实例。
<typegroup name="Jobs">
<itemtype
generate="true"
code="UsersFindCronJob"
extends="CronJob"
jaloclass="de.hybris.training.core.jalo.UsersFindCronJob"
autocreate="true">
<attributes>
<attribute qualifier="firstName" type="java.lang.String">
<modifiers/>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
</typegroup>
<bean id="usersFindJob" class="de.hybris.training.core.job.UsersFindJob"
parent="abstractJobPerformable"/>
package de.hybris.training.core.job;
import de.hybris.platform.cronjob.enums.CronJobResult;
import de.hybris.platform.cronjob.enums.CronJobStatus;
import de.hybris.platform.servicelayer.cronjob.AbstractJobPerformable;
import de.hybris.platform.servicelayer.cronjob.PerformResult;
import de.hybris.training.core.model.UsersFindCronJobModel;
public class UsersFindJob extends AbstractJobPerformable<UsersFindCronJobModel> {
@Override
public PerformResult perform(UsersFindCronJobModel cronJobModel) {
try {
// Retrieve firstName from the cronJob
String firstName = cronJobModel.getFirstName();
// Display Hello firstName
System.out.println("Hello " + firstName);
// In case of success return result: SUCCESS and status: FINISHED
return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
} catch(Exception e) {
// In case of exception return result: ERROR and status: ABORTED
return new PerformResult(CronJobResult.ERROR, CronJobStatus.ABORTED);
}
}
}
/*
* ----------------------------------------------------------------
* --- WARNING: THIS FILE IS GENERATED AND WILL BE OVERWRITTEN! ---
* --- Generated at 09.Nis.2018 22:52:22 ---
* ----------------------------------------------------------------
*
* [y] hybris Platform
*
* Copyright (c) 2000-2016 SAP SE
* All rights reserved.
*
* This software is the confidential and proprietary information of SAP
* Hybris ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with the
* terms of the license agreement you entered into with SAP Hybris.
*
*/
package de.hybris.training.core.model;
import de.hybris.bootstrap.annotations.Accessor;
import de.hybris.platform.core.model.ItemModel;
import de.hybris.platform.cronjob.model.CronJobModel;
import de.hybris.platform.cronjob.model.JobModel;
import de.hybris.platform.servicelayer.model.ItemModelContext;
/**
* Generated model class for type UsersFindCronJob first defined at extension trainingcore.
*/
@SuppressWarnings("all")
public class UsersFindCronJobModel extends CronJobModel
{
/**<i>Generated model type code constant.</i>*/
public static final String _TYPECODE = "UsersFindCronJob";
/** <i>Generated constant</i> - Attribute key of <code>UsersFindCronJob.firstName</code> attribute defined at extension <code>trainingcore</code>. */
public static final String FIRSTNAME = "firstName";
/**
* <i>Generated constructor</i> - Default constructor for generic creation.
*/
public UsersFindCronJobModel()
{
super();
}
/**
* <i>Generated constructor</i> - Default constructor for creation with existing context
* @param ctx the model context to be injected, must not be null
*/
public UsersFindCronJobModel(final ItemModelContext ctx)
{
super(ctx);
}
/**
* <i>Generated constructor</i> - Constructor with all mandatory attributes.
* @deprecated since 4.1.1 Please use the default constructor without parameters
* @param _job initial attribute declared by type <code>CronJob</code> at extension <code>processing</code>
*/
@Deprecated
public UsersFindCronJobModel(final JobModel _job)
{
super();
setJob(_job);
}
/**
* <i>Generated constructor</i> - for all mandatory and initial attributes.
* @deprecated since 4.1.1 Please use the default constructor without parameters
* @param _job initial attribute declared by type <code>CronJob</code> at extension <code>processing</code>
* @param _owner initial attribute declared by type <code>Item</code> at extension <code>core</code>
*/
@Deprecated
public UsersFindCronJobModel(final JobModel _job, final ItemModel _owner)
{
super();
setJob(_job);
setOwner(_owner);
}
/**
* <i>Generated method</i> - Getter of the <code>UsersFindCronJob.firstName</code> attribute defined at extension <code>trainingcore</code>.
* @return the firstName
*/
@Accessor(qualifier = "firstName", type = Accessor.Type.GETTER)
public String getFirstName()
{
return getPersistenceContext().getPropertyValue(FIRSTNAME);
}
/**
* <i>Generated method</i> - Setter of <code>UsersFindCronJob.firstName</code> attribute defined at extension <code>trainingcore</code>.
*
* @param value the firstName
*/
@Accessor(qualifier = "firstName", type = Accessor.Type.SETTER)
public void setFirstName(final String value)
{
getPersistenceContext().setPropertyValue(FIRSTNAME, value);
}
}
/*
* ----------------------------------------------------------------
* --- WARNING: THIS FILE IS GENERATED AND WILL BE OVERWRITTEN! ---
* --- Generated at 09.Nis.2018 22:52:22 ---
* ----------------------------------------------------------------
*
* [y] hybris Platform
*
* Copyright (c) 2000-2016 SAP SE
* All rights reserved.
*
* This software is the confidential and proprietary information of SAP
* Hybris ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with the
* terms of the license agreement you entered into with SAP Hybris.
*
*/
package de.hybris.training.core.jalo;
import de.hybris.platform.cronjob.jalo.CronJob;
import de.hybris.platform.jalo.Item.AttributeMode;
import de.hybris.platform.jalo.SessionContext;
import de.hybris.training.core.constants.TrainingCoreConstants;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Generated class for type {@link de.hybris.training.core.jalo.UsersFindCronJob UsersFindCronJob}.
*/
@SuppressWarnings({"deprecation","unused","cast","PMD"})
public abstract class GeneratedUsersFindCronJob extends CronJob
{
/** Qualifier of the <code>UsersFindCronJob.firstName</code> attribute **/
public static final String FIRSTNAME = "firstName";
protected static final Map<String, AttributeMode> DEFAULT_INITIAL_ATTRIBUTES;
static
{
final Map<String, AttributeMode> tmp = new HashMap<String, AttributeMode>(CronJob.DEFAULT_INITIAL_ATTRIBUTES);
tmp.put(FIRSTNAME, AttributeMode.INITIAL);
DEFAULT_INITIAL_ATTRIBUTES = Collections.unmodifiableMap(tmp);
}
@Override
protected Map<String, AttributeMode> getDefaultAttributeModes()
{
return DEFAULT_INITIAL_ATTRIBUTES;
}
/**
* <i>Generated method</i> - Getter of the <code>UsersFindCronJob.firstName</code> attribute.
* @return the firstName
*/
public String getFirstName(final SessionContext ctx)
{
return (String)getProperty( ctx, FIRSTNAME);
}
/**
* <i>Generated method</i> - Getter of the <code>UsersFindCronJob.firstName</code> attribute.
* @return the firstName
*/
public String getFirstName()
{
return getFirstName( getSession().getSessionContext() );
}
/**
* <i>Generated method</i> - Setter of the <code>UsersFindCronJob.firstName</code> attribute.
* @param value the firstName
*/
public void setFirstName(final SessionContext ctx, final String value)
{
setProperty(ctx, FIRSTNAME,value);
}
/**
* <i>Generated method</i> - Setter of the <code>UsersFindCronJob.firstName</code> attribute.
* @param value the firstName
*/
public void setFirstName(final String value)
{
setFirstName( getSession().getSessionContext(), value );
}
}
INSERT_UPDATE UsersFindCronJob ; code[unique=true] ; job(code) ; firstName ; usersFindCronJob ; usersFindJob ; Mouad
我也试图导入那个Impex,但它说它无效。
答案 0 :(得分:2)
我认为您只是错过了更新系统。然后,您可以使用Impex下方或Backoffice创建作业实例。
Platform > Update
只选择Update running system
复选框和扩展程序的基本数据。
如果您处于无法运行基本数据(例如生产)的情况,则需要在更新后明确运行ServiceLayerJob
。
点击更新按钮
INSERT_UPDATE UsersFindCronJob ; code[unique=true] ; job(code) ; firstName ;
; usersFindCronJob ; usersFindJob ; Mouad ;
你没有运行你需要在Impex下运行的必要数据的情况(如@Johannes所述)
INSERT_UPDATE ServicelayerJob;code[unique=true];springId;
;usersFindJob;usersFindJob
答案 1 :(得分:0)
首先,您需要通过新行分隔数据中的impex标题:
INSERT_UPDATE UsersFindCronJob;code[unique=true];job(code);firstName
;usersFindCronJob;usersFindJob;Mouad
然后你也错过了创建Job本身的部分:
INSERT_UPDATE ServicelayerJob;code[unique=true];springId;
;usersFindJob;usersFindJob
答案 2 :(得分:-1)
创建自定义cronjob时,需要更新创建的“自定义cronjob”。
****我们做的错误是在编写自定义cronjob时更新以下这些语句:**** INSERT_UPDATE ServicelayerJob; code [unique = true]; springId;
INSERT_UPDATE Cronjob; code [unique = true]; job(code); singleExecutable; sessionLanguage(isocode) ****实际上,我们需要编写以下语句:****
INSERT_UPDATE ServicelayerJob; code [unique = true]; springId;
INSERT_UPDATE; code [unique = true]; job(code); singleExecutable; sessionLanguage(isocode)
请注意,如果您在自定义cronjob中添加的属性是强制性的,则还需要更新这些属性,例如:
INSERT_UPDATE; code [unique = true]; job(code); singleExecutable; sessionLanguage(isocode);