forked from sakaiproject/sakai
-
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.
SAK-41216 Enable caching for Sakai Person (sakaiproject#6489)
- Loading branch information
1 parent
ae917ec
commit b36ebc4
Showing
4 changed files
with
11 additions
and
119 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,20 +23,12 @@ | |
|
||
import java.io.BufferedInputStream; | ||
import java.io.BufferedOutputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.sql.Blob; | ||
import java.sql.SQLException; | ||
|
||
import javax.sql.rowset.serial.SerialBlob; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import org.sakaiproject.api.common.edu.person.InetOrgPerson; | ||
import org.sakaiproject.api.common.edu.person.OrganizationalPerson; | ||
import org.sakaiproject.api.common.edu.person.Person; | ||
import org.sakaiproject.component.cover.ServerConfigurationService; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Lance Speelmon </a> | ||
|
@@ -537,108 +529,4 @@ public void setSecretary(String secretary) | |
{ | ||
this.secretary = secretary; | ||
} | ||
|
||
public Blob getBlobImage() | ||
{ | ||
if (this.jpegPhoto == null || jpegPhoto.length < 1 || ServerConfigurationService.getString("profile.photoRepositoryPath", null) != null) | ||
{ | ||
return null; | ||
} | ||
try { | ||
return new SerialBlob(this.jpegPhoto); | ||
} catch (SQLException e) { | ||
log.warn(e.getMessage(), e); | ||
return null; | ||
} | ||
} | ||
|
||
public void setBlobImage(Blob blobImage) | ||
{ | ||
this.jpegPhoto = toByteArray(blobImage); | ||
} | ||
|
||
private byte[] toByteArray(Blob fromBlob) | ||
{ | ||
if (log.isDebugEnabled()) | ||
{ | ||
log.debug("toByteArray(Blob " + fromBlob + ")"); | ||
} | ||
|
||
try | ||
{ | ||
if (fromBlob == null || fromBlob.length() < 1) | ||
{ | ||
return null; | ||
} | ||
} | ||
catch (SQLException e1) | ||
{ | ||
log.error(e1.getMessage(), e1); | ||
} | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
try | ||
{ | ||
return toByteArray(fromBlob, baos); | ||
} | ||
catch (Exception e) | ||
{ | ||
log.error(e.getMessage(), e); | ||
throw new RuntimeException(e); | ||
} | ||
finally | ||
{ | ||
if (baos != null) | ||
{ | ||
try | ||
{ | ||
baos.close(); | ||
} | ||
catch (IOException ex) | ||
{ | ||
log.error(ex.getMessage(), ex); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private byte[] toByteArray(Blob fromBlob, ByteArrayOutputStream baos) throws SQLException, IOException | ||
{ | ||
if (log.isDebugEnabled()) | ||
{ | ||
log.debug("toByteArray(Blob " + fromBlob + ", ByteArrayOutputStream " + baos + ")"); | ||
} | ||
|
||
if (fromBlob == null || fromBlob.length() < 1 || ServerConfigurationService.getString("profile.photoRepositoryPath", null) != null) | ||
{ | ||
return null; | ||
} | ||
byte[] buf = new byte[4000]; | ||
InputStream is = fromBlob.getBinaryStream(); | ||
try | ||
{ | ||
for (;;) | ||
{ | ||
int dataSize = is.read(buf); | ||
|
||
if (dataSize == -1) break; | ||
baos.write(buf, 0, dataSize); | ||
} | ||
} | ||
finally | ||
{ | ||
if (is != null) | ||
{ | ||
try | ||
{ | ||
is.close(); | ||
} | ||
catch (IOException ex) | ||
{ | ||
log.error(ex.getMessage(), ex); | ||
} | ||
} | ||
} | ||
return baos.toByteArray(); | ||
} | ||
|
||
} |
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