Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
0ef87ab3
Commit
0ef87ab3
authored
16 years ago
by
tpylak
Browse files
Options
Downloads
Patches
Plain Diff
LMS-590 sample browser: fix dependencies
SVN: 8532
parent
05058114
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/util/SampleOwnerFinder.java
+172
-0
172 additions, 0 deletions
...is/generic/server/business/bo/util/SampleOwnerFinder.java
with
172 additions
and
0 deletions
openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/util/SampleOwnerFinder.java
0 → 100644
+
172
−
0
View file @
0ef87ab3
/*
* Copyright 2008 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
ch.systemsx.cisd.openbis.generic.server.business.bo.util
;
import
ch.systemsx.cisd.common.exceptions.InternalErr
;
import
ch.systemsx.cisd.common.exceptions.UserFailureException
;
import
ch.systemsx.cisd.openbis.generic.server.dataaccess.IAuthorizationDAOFactory
;
import
ch.systemsx.cisd.openbis.generic.server.util.GroupIdentifierHelper
;
import
ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE
;
import
ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE
;
import
ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE
;
import
ch.systemsx.cisd.openbis.generic.shared.dto.exception.UndefinedGroupException
;
import
ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier
;
import
ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier
;
import
ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleOwnerIdentifier
;
/**
* Finds a group or database instance for a given owner identifier.
*
* @author Tomasz Pylak
*/
public
class
SampleOwnerFinder
{
private
final
IAuthorizationDAOFactory
daoFactory
;
private
final
PersonPE
personPE
;
public
SampleOwnerFinder
(
final
IAuthorizationDAOFactory
daoFactory
,
final
PersonPE
personPE
)
{
assert
daoFactory
!=
null
:
"Unspecified DAOFactory"
;
assert
personPE
!=
null
:
"Unspecified person"
;
this
.
daoFactory
=
daoFactory
;
this
.
personPE
=
personPE
;
}
public
SampleOwner
figureSampleOwner
(
final
SampleOwnerIdentifier
owner
)
{
final
SampleOwner
ownerId
=
tryFigureSampleOwner
(
owner
);
if
(
ownerId
==
null
)
{
throw
UserFailureException
.
fromTemplate
(
"Incorrect group or database name in '%s'"
,
owner
);
}
return
ownerId
;
}
// determines the owner of the sample if it belongs to the home group or home database
public
SampleOwner
tryFigureSampleOwner
(
final
SampleOwnerIdentifier
owner
)
{
if
(
owner
.
isDatabaseInstanceLevel
())
{
final
DatabaseInstanceIdentifier
databaseInstanceIdentifier
=
owner
.
getDatabaseInstanceLevel
();
return
tryFigureSampleDatabaseOwner
(
databaseInstanceIdentifier
);
}
else
if
(
owner
.
isGroupLevel
())
{
return
tryFigureSampleGroupOwner
(
owner
);
}
else
throw
InternalErr
.
error
();
}
private
SampleOwner
tryFigureSampleGroupOwner
(
final
SampleOwnerIdentifier
owner
)
{
if
(
owner
.
isInsideHomeGroup
())
{
return
createHomeGroupOwner
(
owner
);
}
else
{
final
GroupIdentifier
groupIdentifier
=
owner
.
getGroupLevel
();
return
tryFindAbsoluteGroupOwner
(
groupIdentifier
);
}
}
private
SampleOwner
tryFigureSampleDatabaseOwner
(
final
DatabaseInstanceIdentifier
databaseInstanceIdentifier
)
{
final
DatabaseInstancePE
databaseInstance
=
GroupIdentifierHelper
.
tryGetDatabaseInstance
(
databaseInstanceIdentifier
,
daoFactory
);
if
(
databaseInstance
==
null
)
{
return
null
;
}
return
SampleOwner
.
createDatabaseInstance
(
databaseInstance
);
}
private
SampleOwner
tryFindAbsoluteGroupOwner
(
final
GroupIdentifier
groupIdentifier
)
{
final
GroupPE
group
=
GroupIdentifierHelper
.
tryGetGroup
(
groupIdentifier
,
personPE
,
daoFactory
);
if
(
group
==
null
)
{
return
null
;
}
return
SampleOwner
.
createGroup
(
group
);
}
private
SampleOwner
createHomeGroupOwner
(
final
SampleOwnerIdentifier
identifier
)
{
final
GroupPE
homeGroup
=
personPE
.
getHomeGroup
();
if
(
homeGroup
==
null
)
{
throw
new
UndefinedGroupException
();
}
return
SampleOwner
.
createGroup
(
homeGroup
);
}
/**
* Determines who is the "owner" of the sample: the group or to the database instance. Stores
* the owners id.
*/
public
static
class
SampleOwner
{
// if filled, databaseInstanceOrNull must be null
private
GroupPE
groupOrNull
;
// if filled, groupOrNull must be null
private
DatabaseInstancePE
databaseInstanceOrNull
;
public
SampleOwner
(
GroupPE
groupOrNull
,
DatabaseInstancePE
databaseInstanceOrNull
)
{
assert
groupOrNull
==
null
||
databaseInstanceOrNull
==
null
;
assert
groupOrNull
!=
null
||
databaseInstanceOrNull
!=
null
;
this
.
groupOrNull
=
groupOrNull
;
this
.
databaseInstanceOrNull
=
databaseInstanceOrNull
;
}
public
static
SampleOwner
createGroup
(
GroupPE
group
)
{
return
new
SampleOwner
(
group
,
null
);
}
public
static
SampleOwner
createDatabaseInstance
(
DatabaseInstancePE
databaseInstance
)
{
return
new
SampleOwner
(
null
,
databaseInstance
);
}
public
boolean
isGroupLevel
()
{
return
groupOrNull
!=
null
;
}
public
boolean
isDatabaseInstanceLevel
()
{
return
databaseInstanceOrNull
!=
null
;
}
public
GroupPE
tryGetGroup
()
{
return
groupOrNull
;
}
public
DatabaseInstancePE
tryGetDatabaseInstance
()
{
return
databaseInstanceOrNull
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment