on 2018 Sep 24 11:46 AM
Hi everyone! I analyze impex import result errors by using use the collectImportErrors method of the ImportService class (see link). According to Import API (see link) value lines could be either:
completely skipped (in case when some mandatory attributes in the line are missing or not resolved) - in this case the entity is NOT updated/created
partially imported (despite the fact that maybe other non-mandatory attributes are not resolved) - in this case entity IS created/updated.
My question is: is it possible to tell which is the case based on ImpExLineErrorType enum? I would really like to be able to tell, if the entity was created/updated during import or not.
This enum contains the following values: PARTIALLY_PROCESSED, NOT_PROCESSED, PARTIALLY_PROCESSED_WITH_ERROR, NOT_PROCESSED_WITH_ERROR, WRONG_OR_MISSING_HEADER, NOT_PROCESSED_CONFLICTING, NOT_EXISTING_ITEM, REFERENCE_VIOLATION, CANNOT_REMOVE_ITEM, INVALID_DATA_FORMAT, UNKNOWN.
Thanks in advance!
Request clarification before answering.
for more information please refer the below link: https://help.hybris.com/6.7.0/hcd/9375fcee679048da9e1dc7f580cb0ed9.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.salon.integration.exception.ImportDataException;
import com.salon.integration.exception.InsufficientDataException;
import com.salon.integration.service.SalonIntegrationDataLoadService;
import de.hybris.platform.impex.jalo.ImpExException;
import de.hybris.platform.servicelayer.impex.ImpExError;
import de.hybris.platform.servicelayer.impex.ImpExResource;
import de.hybris.platform.servicelayer.impex.ImpExValueLineError.ImpExLineErrorType;
import de.hybris.platform.servicelayer.impex.ImportResult;
import de.hybris.platform.servicelayer.impex.ImportService;
import de.hybris.platform.servicelayer.impex.impl.StreamBasedImpExResource;
import de.hybris.platform.servicelayer.impex.impl.ValueLineError;
class ImportData{
private static final Logger LOG = LoggerFactory.getLogger(ImportData.class);
public ImportResult importData(String json) throws ImportDataException {
final InputStream resourceAsStream = new ByteArrayInputStream(json.getBytes());
final ImpExResource resource = new StreamBasedImpExResource(resourceAsStream, UTF_8);
ImportResult result=null;
result = getImportService().importData(resource);
final Stream<? extends ImpExError> errors = getImportService().collectImportErrors(result);
List<ImpExLineErrorType> list = errors.filter(e -> e instanceof ValueLineError).map(ValueLineError.class::cast)
.map((n) -> n.getErrorType())
.collect(Collectors.toList());
//ImpExLineErrorType.NOT_PROCESSED implies entity is neither completely created nor updated
if(list.contains(ImpExLineErrorType.NOT_PROCESSED))
{
LOG.info("mandatory attribute is null");
}
if(list.contains(ImpExLineErrorType.REFERENCE_VIOLATION))
{
LOG.info("some non-mandatory attribute is missing ant the import has some unresolved lines,
so the entity is partially imported");
}
return result;
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.