Skip to content

Commit

Permalink
Add implementations for model objects of Devfile
Browse files Browse the repository at this point in the history
Signed-off-by: Sergii Leshchenko <sleshche@redhat.com>
  • Loading branch information
sleshchenko committed Apr 2, 2019
1 parent d3d1f22 commit 4957200
Show file tree
Hide file tree
Showing 13 changed files with 1,391 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ public WorkspaceConfigImpl getConfig() {
return config;
}

@Override
public Devfile getDevfile() {
throw new UnsupportedOperationException("Devfile is not supported by GWT IDE");
}

@Override
public Map<String, String> getAttributes() {
if (attributes == null) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.eclipse.che.api.core.model.workspace.Workspace;
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig;
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
import org.eclipse.che.api.core.model.workspace.devfile.Devfile;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.persistence.descriptors.DescriptorEvent;
import org.eclipse.persistence.descriptors.DescriptorEventAdapter;
Expand Down Expand Up @@ -91,8 +90,6 @@ public static WorkspaceImplBuilder builder() {
@JoinColumn(name = "config_id")
private WorkspaceConfigImpl config;

@Transient private DevfileImpl devfile;

@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "workspace_attributes", joinColumns = @JoinColumn(name = "workspace_id"))
@MapKeyColumn(name = "attributes_key")
Expand All @@ -119,7 +116,6 @@ public WorkspaceImpl(String id, Account account, WorkspaceConfig config) {
public WorkspaceImpl(
String id,
Account account,
Devfile devfile,
Runtime runtime,
Map<String, String> attributes,
boolean isTemporary,
Expand All @@ -128,9 +124,6 @@ public WorkspaceImpl(
if (account != null) {
this.account = new AccountImpl(account);
}
if (devfile != null) {
this.devfile = new DevfileImpl(devfile);
}
if (runtime != null) {
this.runtime =
new RuntimeImpl(
Expand Down Expand Up @@ -223,11 +216,6 @@ public WorkspaceConfigImpl getConfig() {
return config;
}

@Override
public DevfileImpl getDevfile() {
return devfile;
}

public void setConfig(WorkspaceConfigImpl config) {
this.config = config;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.workspace.server.model.impl.devfile;

import java.util.Objects;
import org.eclipse.che.api.core.model.workspace.devfile.Action;

/** @author Sergii Leshchenko */
public class ActionImpl implements Action {

private String type;
private String component;
private String command;
private String workdir;

public ActionImpl() {}

public ActionImpl(String type, String component, String command, String workdir) {
this.type = type;
this.component = component;
this.command = command;
this.workdir = workdir;
}

public ActionImpl(Action action) {
this(action.getType(), action.getComponent(), action.getCommand(), action.getWorkdir());
}

@Override
public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

@Override
public String getComponent() {
return component;
}

public void setComponent(String component) {
this.component = component;
}

@Override
public String getCommand() {
return command;
}

public void setCommand(String command) {
this.command = command;
}

@Override
public String getWorkdir() {
return workdir;
}

public void setWorkdir(String workdir) {
this.workdir = workdir;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ActionImpl)) {
return false;
}
ActionImpl action = (ActionImpl) o;
return Objects.equals(getType(), action.getType())
&& Objects.equals(getComponent(), action.getComponent())
&& Objects.equals(getCommand(), action.getCommand())
&& Objects.equals(getWorkdir(), action.getWorkdir());
}

@Override
public int hashCode() {
return Objects.hash(getType(), getComponent(), getCommand(), getWorkdir());
}

@Override
public String toString() {
return "ActionImpl{"
+ "type='"
+ type
+ '\''
+ ", component='"
+ component
+ '\''
+ ", command='"
+ command
+ '\''
+ ", workdir='"
+ workdir
+ '\''
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.workspace.server.model.impl.devfile;

import static java.util.stream.Collectors.toCollection;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.eclipse.che.api.core.model.workspace.devfile.Action;
import org.eclipse.che.api.core.model.workspace.devfile.Command;

/** @author Sergii Leshchenko */
public class CommandImpl implements Command {

private String name;
private List<ActionImpl> actions;
private Map<String, String> attributes;

public CommandImpl() {}

public CommandImpl(String name, List<? extends Action> actions, Map<String, String> attributes) {
this.name = name;
if (actions != null) {
this.actions = actions.stream().map(ActionImpl::new).collect(toCollection(ArrayList::new));
}
if (attributes != null) {
this.attributes = new HashMap<>(attributes);
}
}

public CommandImpl(Command command) {
this(command.getName(), command.getActions(), command.getAttributes());
}

@Override
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public List<ActionImpl> getActions() {
if (actions == null) {
actions = new ArrayList<>();
}
return actions;
}

public void setActions(List<ActionImpl> actions) {
this.actions = actions;
}

@Override
public Map<String, String> getAttributes() {
if (attributes == null) {
attributes = new HashMap<>();
}
return attributes;
}

public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof CommandImpl)) {
return false;
}
CommandImpl command = (CommandImpl) o;
return Objects.equals(getName(), command.getName())
&& Objects.equals(getActions(), command.getActions())
&& Objects.equals(getAttributes(), command.getAttributes());
}

@Override
public int hashCode() {
return Objects.hash(getName(), getActions(), getAttributes());
}

@Override
public String toString() {
return "CommandImpl{"
+ "name='"
+ name
+ '\''
+ ", actions="
+ actions
+ ", attributes="
+ attributes
+ '}';
}
}
Loading

0 comments on commit 4957200

Please sign in to comment.