forked from Catrobat/HardwarePlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read Only backend programming, some programm flow issues need to be r…
…esolved, but routines of back and frontend should work fine
- Loading branch information
1 parent
6695292
commit b042701
Showing
14 changed files
with
570 additions
and
17 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/org/catrobat/jira/adminhelper/activeobject/ReadOnlyHdwGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/catrobat/jira/adminhelper/activeobject/ReadOnlyHdwGroupService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/org/catrobat/jira/adminhelper/activeobject/ReadOnlyHdwGroupServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/catrobat/jira/adminhelper/activeobject/ReadOnlyHdwUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/catrobat/jira/adminhelper/activeobject/ReadOnlyHdwUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/org/catrobat/jira/adminhelper/activeobject/ReadOnlyHdwUserServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.