Skip to content

Commit

Permalink
This is a combination of 3 commits. (#2270)
Browse files Browse the repository at this point in the history
adding error message when trying to add deleted device to jobs

Signed-off-by: ana.albic.comtrade <Ana.Albic@comtrade.com>
  • Loading branch information
ct-anaalbic authored and Coduz committed Jan 7, 2019
1 parent e4bc355 commit 3a94bda
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
Expand Up @@ -11,9 +11,9 @@
*******************************************************************************/
package org.eclipse.kapua.app.console.module.job.server;

import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException;
import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet;
Expand All @@ -37,9 +37,9 @@
import org.eclipse.kapua.service.job.targets.JobTargetListResult;
import org.eclipse.kapua.service.job.targets.JobTargetQuery;
import org.eclipse.kapua.service.job.targets.JobTargetService;

import java.util.ArrayList;
import java.util.List;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;

public class GwtJobTargetServiceImpl extends KapuaRemoteServiceServlet implements GwtJobTargetService {

Expand Down Expand Up @@ -108,27 +108,30 @@ public List<GwtJobTarget> create(GwtXSRFToken xsrfToken, String scopeId, String
List<GwtJobTarget> existingTargets = findByJobId(scopeId, jobId, false);
List<GwtJobTarget> gwtJobTargetList = new ArrayList<GwtJobTarget>();
try {

for (GwtJobTargetCreator gwtJobTargetCreator : gwtJobTargetCreatorList) {
if (findExtistingTarget(gwtJobTargetCreator.getJobTargetId(), existingTargets)) {
continue;
}
KapuaId creatorScopeId = KapuaEid.parseCompactId(gwtJobTargetCreator.getScopeId());
JobTargetCreator jobTargetCreator = JOB_TARGET_FACTORY.newCreator(creatorScopeId);
jobTargetCreator.setJobId(GwtKapuaCommonsModelConverter.convertKapuaId(gwtJobTargetCreator.getJobId()));
jobTargetCreator.setJobTargetId(GwtKapuaCommonsModelConverter.convertKapuaId(gwtJobTargetCreator.getJobTargetId()));

//
// Create the Job Target
JobTarget jobTarget = JOB_TARGET_SERVICE.create(jobTargetCreator);

// convert to GwtJobTarget and return
gwtJobTargetList.add(KapuaGwtJobModelConverter.convertJobTarget(jobTarget));
Device device = DEVICE_REGISTRY_SERVICE.find(KapuaEid.parseCompactId(gwtJobTargetCreator.getScopeId()), KapuaEid.parseCompactId(gwtJobTargetCreator.getJobTargetId()));
if (device != null) {
KapuaId creatorScopeId = KapuaEid.parseCompactId(gwtJobTargetCreator.getScopeId());
JobTargetCreator jobTargetCreator = JOB_TARGET_FACTORY.newCreator(creatorScopeId);
jobTargetCreator.setJobId(GwtKapuaCommonsModelConverter.convertKapuaId(gwtJobTargetCreator.getJobId()));
jobTargetCreator.setJobTargetId(GwtKapuaCommonsModelConverter.convertKapuaId(gwtJobTargetCreator.getJobTargetId()));

// Create the Job Target
JobTarget jobTarget = JOB_TARGET_SERVICE.create(jobTargetCreator);

// convert to GwtJobTarget and return
gwtJobTargetList.add(KapuaGwtJobModelConverter.convertJobTarget(jobTarget));
//
} else {
throw new KapuaEntityNotFoundException(Device.TYPE, gwtJobTargetCreator.getClientId());
}
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}

return gwtJobTargetList;
}

Expand Down
Expand Up @@ -17,6 +17,16 @@ public class GwtJobTargetCreator extends GwtEntityCreator {

private String jobId;
private String jobTargetId;
private String clientId;


public String getClientId() {
return clientId;
}

public void setClientId(String clientId) {
this.clientId = clientId;
}

public String getJobId() {
return jobId;
Expand Down
Expand Up @@ -83,6 +83,7 @@ public static GwtJobTarget convertJobTarget(JobTarget jobTarget) {
GwtJobTarget gwtJobTarget = new GwtJobTarget();
KapuaGwtCommonsModelConverter.convertUpdatableEntity(jobTarget, gwtJobTarget);
gwtJobTarget.setJobTargetId(KapuaGwtCommonsModelConverter.convertKapuaId(jobTarget.getJobTargetId()));
gwtJobTarget.setClientId(KapuaGwtCommonsModelConverter.convertKapuaId(jobTarget.getJobTargetId()));
gwtJobTarget.setStatus(jobTarget.getStatus().toString());
gwtJobTarget.setStepIndex(jobTarget.getStepIndex());
gwtJobTarget.setErrorMessage(jobTarget.getException() != null ? jobTarget.getException().getMessage() : null);
Expand Down

0 comments on commit 3a94bda

Please sign in to comment.