vegankid22
vegankid22

Reputation: 1

Can not see cronjob in backoffice on hybris

I want to create custom CronJob. I followed this tutorial, but unfortunately, I am not able to see my job instance in Backoffice.

*-item.xml

        <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>

*spring.xml

<bean id="usersFindJob" class="de.hybris.training.core.job.UsersFindJob"
parent="abstractJobPerformable"/>

UsersFindJob.java

    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);

                }
        }
}

Autogenerated UsersFindCronJobModel

/*
 * ----------------------------------------------------------------
 * --- 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);
    }

}

Autogenerated GeneratedUsersFindCronJob

    /*
 * ----------------------------------------------------------------
 * --- 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 );
    }

}

Impex

INSERT_UPDATE UsersFindCronJob ; code[unique=true] ; job(code) ; firstName ; usersFindCronJob ; usersFindJob ; Mouad

I also tried to import that Impex but it said it is not valid.

Upvotes: 0

Views: 4905

Answers (3)

Siddhant
Siddhant

Reputation: 1

When you create your custom cronjob,then you need to update the "Custom Cronjob" you created.

****What mistake we do is updating these below statements when we write custom cronjob:**** INSERT_UPDATE ServicelayerJob;code[unique=true];springId;

INSERT_UPDATE Cronjob;code[unique=true];job(code);singleExecutable;sessionLanguage(isocode) ****Actually we need to write these below statements:****

INSERT_UPDATE ServicelayerJob;code[unique=true];springId;

INSERT_UPDATE ;code[unique=true];job(code);singleExecutable;sessionLanguage(isocode)

Please note that,if the attributes you added in custom cronjob are mandatory then you need to update those attributes as well,like:

INSERT_UPDATE ;code[unique=true];job(code);singleExecutable;sessionLanguage(isocode);

Upvotes: -1

HybrisHelp
HybrisHelp

Reputation: 5810

I think you only missed to update your system. Then you can create the instance of your job using below Impex or through Backoffice.

To update

  • ant clean all
  • hybrisserver.bat
  • Open HAC (https://localhost:9002/hac/)
  • Go to Platform > Update
  • Only select Update running system checkbox and essential data of your extension.

    If you are in the situation where you can't run essential data(say Production) you need to explicitly run ServiceLayerJob after the update.

  • Click on update button

Run Impex

INSERT_UPDATE UsersFindCronJob ; code[unique=true] ; job(code)    ; firstName ;  
                               ; usersFindCronJob  ; usersFindJob ; Mouad     ;  

The situation where you haven't run essential data you need to run below Impex(as mentioned by @Johannes)

INSERT_UPDATE ServicelayerJob;code[unique=true];springId;
;usersFindJob;usersFindJob

Refer https://wiki.hybris.com/display/R5T/Trail+~+CronJobs

Upvotes: 2

Johannes von Zmuda
Johannes von Zmuda

Reputation: 1822

First, you need to seperate your impex header from your data by a new line:

INSERT_UPDATE UsersFindCronJob;code[unique=true];job(code);firstName
;usersFindCronJob;usersFindJob;Mouad

Then you also missed the part where you create the Job itself:

INSERT_UPDATE ServicelayerJob;code[unique=true];springId;
;usersFindJob;usersFindJob

Upvotes: 0

Related Questions