Skip to content

Commit

Permalink
read Only backend programming, some programm flow issues need to be r…
Browse files Browse the repository at this point in the history
…esolved, but routines of back and frontend should work fine
  • Loading branch information
DLindenbauer committed Dec 27, 2016
1 parent 6695292 commit b042701
Show file tree
Hide file tree
Showing 14 changed files with 570 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.catrobat.jira.adminhelper.activeobject;


import net.java.ao.Entity;

/**
* Created by dominik on 27.12.16.
*/
public interface ReadOnlyHdwGroup extends Entity {

void setGroupName(String group_name);

String getGroupName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.catrobat.jira.adminhelper.activeobject;

import org.catrobat.jira.adminhelper.activeobject.ReadOnlyHdwGroup;

import java.util.List;

/**
* Created by dominik on 27.12.16.
*/
public interface ReadOnlyHdwGroupService {

ReadOnlyHdwGroup setGroupName(String group_name);

ReadOnlyHdwGroup getReadOnlyHdwGroup();

boolean isInReadOnlyGroup(String UserName);

void clearReadOnlyHdwGroups();

List<String> all();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.catrobat.jira.adminhelper.activeobject;

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.crowd.embedded.api.Group;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import net.java.ao.Query;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* Created by dominik on 27.12.16.
*/
public class ReadOnlyHdwGroupServiceImpl implements ReadOnlyHdwGroupService {

private final ActiveObjects ao;

public ReadOnlyHdwGroupServiceImpl(ActiveObjects ao)
{
this.ao = ao;
}
@Override
public ReadOnlyHdwGroup setGroupName(String group_name)
{
group_name = group_name.trim();

ReadOnlyHdwGroup[] groups = ao.find(ReadOnlyHdwGroup.class, Query.select()
.where("upper(\"GROUP_NAME\") = upper(?)", group_name));
if(groups.length == 0)
{
ReadOnlyHdwGroup group = ao.create(ReadOnlyHdwGroup.class);
group.setGroupName(group_name);
group.save();

return group;
}
else
return groups[0];
}

@Override
public ReadOnlyHdwGroup getReadOnlyHdwGroup()
{
ReadOnlyHdwGroup[] groups = ao.find(ReadOnlyHdwGroup.class);
if(groups.length == 0) {
ao.create(ReadOnlyHdwGroup.class).save();
groups = ao.find(ReadOnlyHdwGroup.class);
}
return groups[0];
}


@Override
public boolean isInReadOnlyGroup(String user_name)
{
boolean isInReadOnlyGroup = false;

if(user_name != null)
user_name = user_name.trim();

ApplicationUser user = ComponentAccessor.getUserManager().getUserByName(user_name);
if(user == null)
return true;

Collection<Group> groups_of_user = ComponentAccessor.getGroupManager().getGroupsForUser(user);

for(Group group : groups_of_user)
{
if(ao.find(ReadOnlyHdwGroup.class, Query.select().where("upper(\"GROUP_NAME\") = upper(?)",
group.getName().trim())).length != 0)
{
isInReadOnlyGroup = true;
break;
}
}
return isInReadOnlyGroup;
}

@Override
public void clearReadOnlyHdwGroups()
{
for(ReadOnlyHdwGroup group: ao.find(ReadOnlyHdwGroup.class))
ao.delete(group);
}

@Override
public List<String> all()
{
List<String> groups = new ArrayList<>();

for(ReadOnlyHdwGroup group : ao.find(ReadOnlyHdwGroup.class))
{
groups.add(group.getGroupName());
}
return groups;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.catrobat.jira.adminhelper.activeobject;

/**
* Created by dominik on 26.12.16.
*/

import net.java.ao.Entity;
import net.java.ao.Preload;

@Preload
public interface ReadOnlyHdwUser extends Entity {

void setUserKey(String userKey);

String getUserKey();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.catrobat.jira.adminhelper.activeobject;

import com.atlassian.activeobjects.tx.Transactional;

import java.util.List;

/**
* Created by dominik on 26.12.16.
*/
@Transactional
public interface ReadOnlyHdwUserService {

ReadOnlyHdwUser addUserKey(String userKey);

ReadOnlyHdwUser getReadOnlyHardwareUser();

boolean isReadOnlyHardwareUser(String userKey);

void clearReadOnlyHardwareUsers();

List<String> all();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.catrobat.jira.adminhelper.activeobject;

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;
import net.java.ao.Query;

import java.util.ArrayList;
import java.util.List;

/**
* Created by dominik on 27.12.16.
*/
public class ReadOnlyHdwUserServiceImpl implements ReadOnlyHdwUserService {

private final ActiveObjects ao;

public ReadOnlyHdwUserServiceImpl(ActiveObjects ao)
{
this.ao = ao;
}

@Override
public ReadOnlyHdwUser addUserKey(String userKey)
{
if(userKey == null || userKey.trim().length() == 0)
return null;

userKey = userKey.trim();

ReadOnlyHdwUser[] users = ao.find(ReadOnlyHdwUser.class, Query.select()
.where("upper(\"USER_KEY\") = upper(?)", userKey));

if(users.length == 0)
{
ReadOnlyHdwUser user = ao.create(ReadOnlyHdwUser.class);
user.setUserKey(userKey);
user.save();
return user;
}
else
return users[0];
}

@Override
public ReadOnlyHdwUser getReadOnlyHardwareUser()
{
ReadOnlyHdwUser[] users = ao.find(ReadOnlyHdwUser.class);
if(users.length == 0)
{
ao.create(ReadOnlyHdwUser.class).save();
users = ao.find(ReadOnlyHdwUser.class);
}
return users[0];
}

@Override
public boolean isReadOnlyHardwareUser(String userKey)
{
if(userKey != null)
userKey = userKey.trim();

return ao.find(ReadOnlyHdwUser.class, Query.select()
.where("upper(\"USER_KEY\") = upper(?)", userKey)).length != 0;
}

@Override
public void clearReadOnlyHardwareUsers()
{
for(ReadOnlyHdwUser user: ao.find(ReadOnlyHdwUser.class))
ao.delete(user);
}

@Override
public List<String> all()
{
List<String> users = new ArrayList<String>();
UserManager userManager = ComponentAccessor.getUserManager();
for(ReadOnlyHdwUser user : ao.find(ReadOnlyHdwUser.class))
{
String key = user.getUserKey();
ApplicationUser temp_user = userManager.getUserByKey(key);
String user_name = temp_user.getName();
if(user_name != null)
users.add(user_name);
}
return users;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void upgrade(ModelVersion modelVersion, ActiveObjects activeObjects) {
activeObjects.migrate(AdminHelperConfig.class, ApprovedGroup.class, ApprovedUser.class, Device.class,
DeviceComment.class, GithubTeam.class, Group.class, HardwareModel.class, Lending.class,
OperatingSystem.class, Producer.class, Resource.class, Team.class, TeamToGithubTeam.class,
TeamToGroup.class, TypeOfDevice.class);
TeamToGroup.class, TypeOfDevice.class, ReadOnlyHdwUser.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ public Response setGithubConfig(final JsonConfig jsonConfig, @Context HttpServle
else
return Response.serverError().entity("Github Configuration Settings are not valid").build();

System.out.println("Hello darkness my old friend");
if(jsonConfig.getDefaultGithubTeam() != null)
{
System.out.println("about to save Team" + jsonConfig.getDefaultGithubTeam());
configService.setDefaultGithubTeam(jsonConfig.getDefaultGithubTeam());
}

Expand Down
Loading

0 comments on commit b042701

Please sign in to comment.