code cleanup

V1 file import - added support for more component types
minor improvements
This commit is contained in:
Branislav Stojkovic
2016-11-02 01:04:52 +01:00
parent 94c8512c11
commit ad6e45da23
24 changed files with 285 additions and 139 deletions
@@ -25,7 +25,7 @@ public class PropertyWrapper implements Cloneable {
private boolean changed = false;
private String additionalOptions;
private int sortOrder;
private String[] listItems;
private Object[] listItems;
public PropertyWrapper(String name, Class<?> type, String getter, String setter, boolean defaultable,
IPropertyValidator validator, String additionalOptions, int sortOrder) {
@@ -46,7 +46,7 @@ public class PropertyWrapper implements Cloneable {
if (additionalOptions.startsWith(EditableProperty.DYNAMIC_LIST)) {
String functionName = additionalOptions.substring(EditableProperty.DYNAMIC_LIST.length());
Method listMethod = object.getClass().getMethod(functionName);
listItems = (String[]) listMethod.invoke(object);
listItems = (Object[]) listMethod.invoke(object);
}
}
@@ -112,11 +112,11 @@ public class PropertyWrapper implements Cloneable {
return sortOrder;
}
public String[] getListItems() {
public Object[] getListItems() {
return listItems;
}
public void setOptions(String[] listItems) {
public void setOptions(Object[] listItems) {
this.listItems = listItems;
}
@@ -1,5 +1,12 @@
package org.diylc.core.annotations;
/**
* Tells the system how to represent components in the B.O.M.
*
* @see ComponentDescriptor
*
* @author Branislav Stojkovic
*/
public enum BomPolicy {
SHOW_ALL_NAMES, SHOW_ONLY_TYPE_NAME, NEVER_SHOW,
}
@@ -7,7 +7,9 @@ import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
/**
* Annotation for {@link IDIYComponent} implementation. Describes component properties.
* Annotation that needs to be used for each {@link IDIYComponent} implementation. Describes
* component properties and how component should be represented and interact with the rest of the
* system.
*
* @author Branislav Stojkovic
*/
@@ -9,7 +9,24 @@ import org.diylc.core.IPropertyValidator;
/**
* Used to annotate editable component property. Editable property XYZ must have both getter and
* setter named <code>getXYZ</code> and <code>setXYZ</code> respectively and this annotation must be
* placed on the getter method.
* placed on the getter method. <br>
* <br>
* In the example below, {@code category} is the property we want to edit and
* {@code getCategories()} provides a list of available values for category.
*
* <pre>
* <code>
* &#64;EditableProperty(additionalOptions = EditableProperty.DYNAMIC_LIST
* + "getCategories")
* public String getCategory() {
* return category;
* }
*
* public String[] getCategories() {
* return categories;
* }
* </code>
* </pre>
*
* @author Branislav Stojkovic
*/
@@ -4,7 +4,18 @@ import java.util.List;
import org.diylc.core.IDIYComponent;
/**
* Interface for creating components automatically each time a component is created by the user.
*
* @author Branislav Stojkovic
*/
public interface IAutoCreator {
/**
* @param lastAdded the component created by the user
* @return {@link List} of {@link IDIYComponent}s that will be automatically created as a result.
* Empty {@link List} or {@code null} are valid responses for cases when no components
* should be auto-created.
*/
public List<IDIYComponent<?>> createIfNeeded(IDIYComponent<?> lastAdded);
}
@@ -1,5 +1,12 @@
package org.diylc.core.annotations;
/**
* Tells the system how keywords should be extracted from a component.
*
* @see ComponentDescriptor
*
* @author Branislav Stojkovic
*/
public enum KeywordPolicy {
/**
* The component is represented with its type.
@@ -4,6 +4,12 @@ import org.diylc.core.IPropertyValidator;
import org.diylc.core.ValidationException;
import org.diylc.core.measures.AbstractMeasure;
/**
* Validates any generic {@link AbstractMeasure} descendants and makes sure that the value is
* positive.
*
* @author Branislav Stojkovic
*/
public class PositiveMeasureValidator implements IPropertyValidator {
@Override
@@ -30,6 +30,8 @@ import com.diyfever.httpproxy.ProxyFactory;
* @author Branislav Stojkovic
*/
public class CloudPresenter {
public static final CloudPresenter Instance = new CloudPresenter();
private static String USERNAME_KEY = "cloud.Username";
private static String TOKEN_KEY = "cloud.token";
@@ -44,15 +46,11 @@ public class CloudPresenter {
private String machineId;
private String[] categories;
private CloudListener listener;
private boolean loggedIn = false;
private CloudPresenter() {}
public CloudPresenter(CloudListener listener) {
this.listener = listener;
}
public IServiceAPI getService() {
private IServiceAPI getService() {
if (service == null) {
serviceUrl =
ConfigurationManager.getInstance().readString(IServiceAPI.URL_KEY, "http://www.diy-fever.com/diylc/api/v1");
@@ -79,7 +77,6 @@ public class CloudPresenter {
LOG.info("Login success");
ConfigurationManager.getInstance().writeValue(USERNAME_KEY, username);
ConfigurationManager.getInstance().writeValue(TOKEN_KEY, res);
listener.loggedIn();
this.loggedIn = true;
return true;
}
@@ -102,7 +99,6 @@ public class CloudPresenter {
return false;
} else {
LOG.info("Login success");
listener.loggedIn();
this.loggedIn = true;
return true;
}
@@ -114,7 +110,6 @@ public class CloudPresenter {
LOG.info("Logged out");
ConfigurationManager.getInstance().writeValue(TOKEN_KEY, null);
this.loggedIn = false;
listener.loggedOut();
}
public boolean isLoggedIn() {
@@ -6,16 +6,14 @@ import org.diylc.plugins.cloud.model.ProjectEntity;
/**
* Used to create paging of the search results. Use
* {@link PagingProvider#startSession(String, String, String)} to start the search session and then
* {@link PagingProvider#hasMoreData()} returns true if there's more data available and
* {@link PagingProvider#requestMoreData()} returns the next page.
* {@link SearchSession#startSession(String, String, String)} to start the search session and then
* {@link SearchSession#hasMoreData()} returns true if there's more data available and
* {@link SearchSession#requestMoreData()} returns the next page.
*
* @author Branislav Stojkovic
*/
public class PagingProvider {
private CloudPresenter cloudPresenter;
public class SearchSession {
private String searchFor;
private String category;
private String sort;
@@ -24,8 +22,7 @@ public class PagingProvider {
private int currentPage;
private List<ProjectEntity> currentResults;
public PagingProvider(CloudPresenter cloudPresenter) {
this.cloudPresenter = cloudPresenter;
public SearchSession() {
}
public List<ProjectEntity> startSession(String searchFor, String category, String sort) throws CloudException {
@@ -34,7 +31,7 @@ public class PagingProvider {
this.sort = sort;
this.currentPage = 1;
return currentResults = cloudPresenter.search(searchFor, category, sort, currentPage, itemsPerPage);
return currentResults = CloudPresenter.Instance.search(searchFor, category, sort, currentPage, itemsPerPage);
}
public boolean hasMoreData() {
@@ -43,6 +40,6 @@ public class PagingProvider {
public List<ProjectEntity> requestMoreData() throws CloudException {
currentPage++;
return currentResults = cloudPresenter.search(searchFor, category, sort, currentPage, itemsPerPage);
return currentResults = CloudPresenter.Instance.search(searchFor, category, sort, currentPage, itemsPerPage);
}
}