Skip to content

Commit

Permalink
Revert "Refactor to change idNum to Integer in Project"
Browse files Browse the repository at this point in the history
This reverts commit 881fc42.
  • Loading branch information
robertsmieja committed Sep 5, 2014
1 parent fc71a36 commit 9c9fc29
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,52 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* mpdelladonna
*
*******************************************************************************/

package edu.wpi.cs.wpisuitetng.modules;

import java.util.HashMap;
import java.util.Map;

import com.google.gson.annotations.Expose;

import edu.wpi.cs.wpisuitetng.Permission;
import edu.wpi.cs.wpisuitetng.modules.core.models.Project;
import edu.wpi.cs.wpisuitetng.modules.core.models.User;

/**
* Defines the behavior for permissions
*
* @author mpdelladonna
*
*/
public abstract class AbstractModel implements Model {

private Map<User, Permission> permissionMap = new HashMap<User, Permission>(); // annotation for User serialization
private Project project;

@Override
public Permission getPermission(User user) {
return permissionMap.get(user);
public Permission getPermission(User u)
{

return permissionMap.get(u);
}

@Override
public void setPermission(Permission permission, User user) {
permissionMap.put(user, permission);
public void setPermission(Permission p, User u)
{
permissionMap.put(u, p);
}

@Override
public Project getProject() {
return project;
}

@Override
public void setProject(Project project) {
this.project = project;
public void setProject(Project p) {
this.project = p;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.gson.GsonBuilder;

import edu.wpi.cs.wpisuitetng.modules.AbstractModel;
import edu.wpi.cs.wpisuitetng.modules.Model;

/**
* The Data Model representation of a Project. Offers
Expand All @@ -33,7 +34,7 @@ public class Project extends AbstractModel
{

private String name;
private Integer idNum;
private String idNum;
private String[] supportedModules;
private User owner;
private ArrayList<User> team;
Expand All @@ -46,49 +47,30 @@ public class Project extends AbstractModel
* @param team - The User[] who are associated with the project
* @param supportedModules - the modules supported by this project
*/
@Deprecated
public Project(String name, String idNum, User owner, User[] team, String[] supportedModules)
{
this(name, Integer.parseInt(idNum), owner, team, supportedModules);
}

/**
* Primary constructor for a Project
* @param name - the project name
* @param idNum - the project ID number as a string
* @param owner - The User who owns this project
* @param team - The User[] who are associated with the project
* @param supportedModules - the modules supported by this project
*/
public Project(String name, Integer idNum, User owner, User[] team, String[] supportedModules) {
this.name = name;
this.idNum = idNum;
this.owner = owner;
this.supportedModules = supportedModules;

if (team != null) {

if(team != null)
{
this.team = new ArrayList<User>(Arrays.asList(team));
} else {
}
else
{
this.team = new ArrayList<User>();
}
}

/**
* Secondary constructor for a Project
* @param name the project name
* @param idNum the ID number to associate with this Project.
*/
@Deprecated
public Project(String name, String idNum) {
this(name, Integer.parseInt(idNum));
}

/**
* Secondary constructor for a Project
* @param name the project name
* @param idNum the ID number to associate with this Project.
*/
public Project(String name, int idNum) {
public Project(String name, String idNum)
{
this.name = name;
this.idNum = idNum;
}
Expand All @@ -99,13 +81,7 @@ public String getName()
return name;
}

@Deprecated
public String getIdNum_Deprecated()
{
return new Integer(this.getIdNum()).toString();
}

public Integer getIdNum()
public String getIdNum()
{
return idNum;
}
Expand All @@ -116,6 +92,10 @@ public void setName(String newName)
this.name = newName;
}

private void setIdNum(String newId)
{
this.idNum = newId;
}

/* database interaction */

Expand Down Expand Up @@ -250,14 +230,14 @@ public Boolean identify(Object o)

if(o instanceof Project)
{
if(((Project) o).getIdNum().equals(this.idNum))
if(((Project) o).getIdNum().equalsIgnoreCase(this.idNum))
{
b = true;
}
}

if(o instanceof String)
if(((String) o).equals((this.idNum)))
if(((String) o).equalsIgnoreCase((this.idNum)))
b = true;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void testSetName()
@Test
public void testGetIdNum()
{
assertTrue(p1.getIdNum_Deprecated().equals("proj1"));
assertTrue(p1.getIdNum().equals("proj1"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public boolean match(Model anObject){
return false;
}
else{
return (anObject.getProject().getIdNum_Deprecated().equals(theProject.getIdNum_Deprecated())) &&
return (anObject.getProject().getIdNum().equals(theProject.getIdNum())) &&
theGetter.invoke(anObjectQueried.cast(anObject)).equals(theGivenValue);
//objects that have the same ProjectID and aFieldName equal to theGivenValue get added to the list
}
Expand Down Expand Up @@ -285,7 +285,7 @@ public <T> List<Model> retrieveAll(T aSample, Project aProject){
List<Model> allResults = theDB.queryByExample(aSample.getClass());
for(Model theModel : allResults) {
if(theModel.getProject() != null &&
theModel.getProject().getIdNum_Deprecated().equalsIgnoreCase(aProject.getIdNum_Deprecated())){
theModel.getProject().getIdNum().equalsIgnoreCase(aProject.getIdNum())){
result.add(theModel);
}
}
Expand Down Expand Up @@ -727,7 +727,7 @@ else if(m.getName().equalsIgnoreCase("get" + aFieldNameList[i])){
result = theDB.query(new Predicate<Model>(){
public boolean match(Model anObject){
try {
return anObject.getProject().getIdNum_Deprecated().equals(aProject.getIdNum_Deprecated()) &&
return anObject.getProject().getIdNum().equals(aProject.getIdNum()) &&
getBack.invoke(anObjectQueried.cast(anObject)).equals(givenValue);
} catch (IllegalArgumentException e) {
e.printStackTrace();
Expand Down Expand Up @@ -814,7 +814,7 @@ else if(m.getName().equalsIgnoreCase("get" + aFieldNameList[i])){
result = theDB.query(new Predicate<Model>(){
public boolean match(Model anObject){
try {
return anObject.getProject().getIdNum_Deprecated().equals(aProject.getIdNum_Deprecated()) &&
return anObject.getProject().getIdNum().equals(aProject.getIdNum()) &&
getBack.invoke(anObjectQueried.cast(anObject)).equals(givenValue);
} catch (IllegalArgumentException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ProjectManager(Data data)
public String advancedGet(Session s, String[] args)
throws WPISuiteException {

return this.getEntity(s, s.getProject().getIdNum_Deprecated())[0].toJson();
return this.getEntity(s, s.getProject().getIdNum())[0].toJson();
}

@Override
Expand All @@ -86,7 +86,7 @@ public Project makeEntity(Session s, String content) throws WPISuiteException {
logger.log(Level.FINE, "New project: "+ p.getName() +" submitted by: "+ theUser.getName() );
p.setOwner(theUser);

if(getEntity(s,p.getIdNum_Deprecated())[0] == null)
if(getEntity(s,p.getIdNum())[0] == null)
{
if(getEntityByName(s, p.getName())[0] == null)
{
Expand Down Expand Up @@ -264,7 +264,7 @@ public Project update(Session s, Project toUpdate, String changeSet) throws WPIS
{
// check for conflict for changing the project name
Project isConflict = getEntityByName(s, change.getName())[0];
if(isConflict != null && !isConflict.getIdNum_Deprecated().equals(change.getIdNum_Deprecated()))
if(isConflict != null && !isConflict.getIdNum().equals(change.getIdNum()))
{
throw new ConflictException("ProjectManager attempted to update a Project's name to be the same as an existing project");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void deserializeProjectFull()
Project inflated = deserializer.fromJson(jsonProject, Project.class);

assertTrue(inflated.getName().equals("TestProj"));
assertTrue(inflated.getIdNum_Deprecated().equals("1"));
assertTrue(inflated.getIdNum().equals("1"));
}

@Test
Expand All @@ -69,7 +69,7 @@ public void deserializeProjectMissingFields()

Project inflated = deserializer.fromJson(jsonProject, Project.class);

assertTrue(inflated.getIdNum_Deprecated().equals("2"));
assertTrue(inflated.getIdNum().equals("2"));
assertTrue(inflated.getName().equals(""));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public List<Model> complexRetrieve(Class andanObjectQueried,
return null;
}
}
).deleteEntity(null, temp.getIdNum_Deprecated());
).deleteEntity(null, temp.getIdNum());
}

@Test
Expand Down Expand Up @@ -381,7 +381,7 @@ public List<Model> complexRetrieve(Class andanObjectQueried,
return null;
}
}
).deleteEntity(tempSession, temp.getIdNum_Deprecated());
).deleteEntity(tempSession, temp.getIdNum());
}

@Test
Expand Down Expand Up @@ -420,7 +420,7 @@ public void testUpdate() throws WPISuiteException

// TODO: find a way to retrieve the User from storage to run assertions on.

assertTrue(newTemp.getIdNum_Deprecated().equals("2"));
assertTrue(newTemp.getIdNum().equals("2"));
assertTrue(newTemp.getName().equals("proj2"));
}

Expand Down

0 comments on commit 9c9fc29

Please sign in to comment.